While Loop

Get help using Construct 2

Post » Sun Mar 04, 2012 7:25 am

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!
B
19
S
5
G
4
Posts: 85
Reputation: 4,920

Post » Sun Mar 04, 2012 7:33 am

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.GenkiGenga2012-03-04 07:34:30
ImageImage
B
72
S
16
G
6
Posts: 1,038
Reputation: 10,448

Post » Sun Mar 04, 2012 7:40 am

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 :)
B
19
S
5
G
4
Posts: 85
Reputation: 4,920

Post » Sun Mar 04, 2012 11:26 am

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

[code]+System: repeat 1000 times
-> do things
+ while condition becomes false
    -> break loop[/code]
Then it's just a matter of knowing what is the maximum loop your games need.Yann2012-03-04 11:27:03
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Sun Mar 04, 2012 2:12 pm

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 :)
B
19
S
5
G
4
Posts: 85
Reputation: 4,920

Post » Sun Mar 04, 2012 8:12 pm

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.
http://dl.dropbox.com/u/5426011/examples%209/while.capx

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.R0J0hound2012-03-04 20:12:57
B
79
S
24
G
52
Posts: 4,723
Reputation: 39,709

Post » Mon Mar 05, 2012 11:48 am

Thanks for the example R0J0hound. That helps!
B
19
S
5
G
4
Posts: 85
Reputation: 4,920


Return to How do I....?

Who is online

Users browsing this forum: cesisco and 15 guests