How do I use while loops w/o crashing the game?

0 favourites
  • 3 posts
From the Asset Store
40 ambient sound loops. A wide selection of looping ambient sounds for different locations.
  • I have a while loop running as a sub-event to "on the start of layout". It looks like this:[/img]

    When I run the game, it crashes. Before, using repeat instead of a while loop worked fine. It doesn't even run indefinitely, it doesn't do anything at all.

  • Loops are all executed in one tick, even if there are wait actions inside. So in your case you are creating an infinite loop and a huge number of wait threads. The rest of the code after "wait" never gets executed (because it can only happen on the next tick). That's why your project freezes.

    Also, when using "While" and there is even a slight possibility of an infinite loop, I recommend adding another condition - "Loopindex<1000". This will ensure that the loop will terminate after 1000 cycles.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks, I didn't think about it that way.

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