Why my "For each" loop does not work?

0 favourites
  • 6 posts
From the Asset Store
2D fighting template based in the game that defined the fighting games genre.
  • I ma de a "For each" loop, thinking if I I make it "for each object" it would pick the object specified each time.

    Apparently it does not. How do I make it work?

    Here is my loop, the changes for "Brick" do not happen when I call the function.

    Here is how I call the function:

    I also noticed a strange behaviour, when I put contents of each function into single function, ordered, which are loops, it wants to run them simultaneously rather than wait until the loop is done.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Where do you call MakeGame? That's important here. You might call it before the Bricks exist

  • I do call it before bricks exist, because I create bricks in a function that is included in "MakeGame"...

    Bricks are created fine, they have ID-s I give them, function "DrawBricks" which is called before "SetLayers".

    I nitpicked the problem to the loop itself:

    Loop happens, but "For each brick" does not pass on the ID it is sorting them by, thus not picking any brick...

    I know a longer workaround for this using "Pick x instance" and just looping it N amount of times.. But this wrong, it should work like this. Or Tutorials should really explain how C3 operates, is it depth first or not and how are references to instances handled?

  • It's because the bricks don't exist yet as all functions run within the same tick. In construct you have to wait for the next tick before the objects become pickable in the other functions. You can add 'wait for previous actions to complete' between the function calls in MakeGame.

  • Ooh, I come from C2, there was no such thing, bummer. I thought whichever comes first, happens first. So its not depth-first...

    Although I do understand the reason to run multiple loops simultaneously.

  • It was the same in C2 as I recall, they only become pickable until next tick. It does run them in order but the instances are not available until the next tick, people would use system waits. 'Wait for previous actions to complete' is a new thing in C3 though.

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