How do I pick family members once each.

0 favourites
  • 4 posts
From the Asset Store
Change the size and position of everything without calculating anything!
  • Trying to think of an elegant solution for this. Each frame, I only want to pick one family member (it can be random or sequential, doesn't matter), but I want to pick them all once before I start again fresh. I want this to be as fast as possible. So the simplest way I guess would be to somehow cycle through them, but I'm not aware of a familymember[index] type solution. Or otherwise, set a bool as false, pick one with a false, set it to true until all are true and then refresh. But that sounds slow.

    So I'm looking for.....

    Every Tick - Pick a random family member that hasn't been picked. Work with that instance.

    When all have been picked once, refresh and start again.

    I suspect that I'm missing something obvious or built in, but I've been away from C2 for a while and I can't think of anything.

  • I would cycle through them by using :

    For 0 to family.count

    where (pick by comparison) family.IID = loopindex

    That cycles through them in order of IID, you would have to work something in for randomness.

  • Using a boolean variable seems like a good solution.

    On every tick -> call Function.ProcessOne()
    
    Function ProcessOne()
       Pick Family where isProcessed=false
           Pick random Family instance -> do something with it, set Family.isProcessed=true
       Else
           Pick All -> Family set isProcessed=false
           call Function.ProcessOne()
    [/code:bv3nyqfd]
    
    There is nothing in this code that could affect performance, it should work very fast. Function will be called recursively only once in many ticks.
  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Thanks, those both work. I'd forgotten that IID actually keeps a sequential list and I believe I'm right in saying that if objects are destroyed or added, it maintains a sequential order, so it was just a case of keeping a global counter and counting up until I hit the count. Fairly simple in the end.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)