While Loop

0 favourites
  • 7 posts
From the Asset Store
SynthWave Loop Pack includes 68 seamless loops, founded on 11 original melodies.
  • Hi guys,

    I'm in need of a while loop for part of my game and I notice there is none. I tried simulating one with two events added together - a for 1 to 10 loop and a flag variable that is either set to 1 or 0 depending on whether or not I want the loop to terminate. This flag variable is set in sub-events of this combination event. When I run this however the loop is not short circuited by the flag variable being set to 1, but rather it keeps looping. I have placed the flag variable first. Is there any way I can simulate a while loop at all? Also I need to submit this to the arcade so non standard plugins may not be an option... :/

    Thanks for your help in advance!

  • Im not sure i exactly understand what you mean but you can make a "group" in your event sheet, then set it to activate/deactivate through system commands.

    So it becomes while "group" is active ==> Do what you want.

    When "group" is deactivated ==> dont do those things.

    Not sure if it helps just giving it a crack lol.

  • Hi GenkiGenga, that wasn't exactly what I was after. I was hoping there was an equivalent to the programming "While Loop" in Construct 2.

    Thanks for trying though :)

  • There's not, a work around would be to set a repeat loop with a high number and to break this loop when the while condition would have become false

    +System: repeat 1000 times
      -> do things
      + while condition becomes false
        -> break loop

    Then it's just a matter of knowing what is the maximum loop your games need.

  • Hi Yann,

    I tried to do that with a for loop but to no avail. Perhaps using a repeat loop might have worked depending on how it is implemented.

    I ended up figuring out a work around though, which was by performing the action every tick except when a condition was false.

    Thanks for your help :)

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Yann's solution works for me, it doesn't matter if it's "for" or "repeat".

    Here is an example where a sprite instantly closes the gap with another sprite.


    I acts just like a "while" loop. If you move Sprite2 out of the path of Sprite then the game will hang as it try's to loop through a billion numbers.

  • Thanks for the example R0J0hound. That helps!

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