Loop weird behavior and issues.

0 favourites
  • 3 posts
From the Asset Store
For Adventure, Action, Heroes, Sci-fi and Action-RPG games.
  • Hello everyone,

    I created a for loop that looks like this:

    https://i.imgur.com/S7RYfyh.png

    My expectation with this is that the for loop will run, ends and then the empty condition-event will execute. Turns out that is not the case. It runs BEFORE the for loop ends.

    Fine. So I do this:

    https://i.imgur.com/lbVxbGA.png

    Guess what, that code that checks if loopindex >= currentWaveEnemyCount? That doesn't run at all. So I put a "DebugText > Set Text to loopindex" inside the for loop to see what that brings. It is 0.

    The weird thing is, in the game, the enemies spawn with 1 second wait time apart just like the for loop code says. But for some odd reason, loopindex is 0.

    What gives?

    Another similar thing. I have a repeat every X seconds event that looks like this:

    https://i.imgur.com/07kUpz4.png

    At first, the event didn't have so many "Call IncrementWaveCount" or "Add 1 to currentWaveID". It was only the highlighted part at the top. I thought that the repeat would happen, passes by all conditions firing the correct one and then firing the bottom highlighted section.

    That doesn't happen. It loops 3 times without executing ANY of the conditions that check IDs and then on ID = 5 it works.

    So I thought I'd force it to work, so I put at each condition the increment call + add 1 and then I removed the bottom highlighted part. I also included an empty event to run after the forloop to stop loop

    Again, with the weirdness, the ID was incremented to 7 in an instant and ALL conditions were run.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I think the loop runs instantly like within the tick which is why loopindex is 0 then the Wait kind of queues up the events after it because it's asynchronous. I don't expect to get normal results when I add a Wait in a loop but I believe this is what happens.

    For enemy spawner behaviour you could try using Timer behaviour on the enemy spawner object itself, this is what I used and gives nice control over system loop.

  • I think the loop runs instantly like within the tick which is why loopindex is 0 then the Wait kind of queues up the events after it because it's asynchronous. I don't expect to get normal results when I add a Wait in a loop but I believe this is what happens.

    For enemy spawner behaviour you could try using Timer behaviour on the enemy spawner object itself, this is what I used and gives nice control over system loop.

    It baffles me that something like "Wait" would mess up loops so much, like if it is a problem, why not disallow waiting in a loop? There are tons of "you can't do this while doing that" warning messages in C3, why isn't this one of them? Just venting though.

    What is weird, is that the Every X loop has the same weird behavior and it doesn't have a wait. Unless you count "Every X" as a wait and in this case, the thing is broken by design.

    Something is odd in how loops function in C3 compared to other engines. I come from Unity and this nonsense doesn't happen there and you could easily add a "wait" to your heart's content or whatever.

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