How do I stop a loop before its suposed to end?

Get help using Construct 2

Post » Thu Dec 10, 2015 5:07 am

I'm at my wits end with this, I'm sure its an easy solve, so I would appreciate the help.

In the game I'm making, I have a layout set up so that when you press a button, I want it to keep appending text on a new line until one of two conditions happen.

for testing it, I set up a button to end the loop, but I cannot get it to work. I've tried doing while loops and adding a [wait 2*loopindex] but keep getting indefinite loops and its not waiting like it should, even when I put a [on button click end loop] in the events.

Any help on this?

I want to start just append text to a text block until either a button is pressed, or a random event (Which is controlled by time and a random number) happens.
B
4
Posts: 5
Reputation: 210

Post » Thu Dec 10, 2015 9:33 am

I would do it without a loop. Make an extra global variable that act like a boolean like 'isAppend=-1'
Then you could use this:

System| isAppend=1 -> 'Append your Text'

Button| on clicked -> System| set isAppend to isAppend*-1

random event triggered -> System| set isAppend to -1
B
24
S
3
G
1
Posts: 451
Reputation: 2,165

Post » Thu Dec 10, 2015 8:06 pm

Thank you. If I add a wait, will this continue to append text until the even or button changes the variable? That's why I figured I needed to use a loop, to keep it going until I'm ready for it to stop. I apologise that I'm not about to just test it, wrong be near a computer until later tonight.
B
4
Posts: 5
Reputation: 210

Post » Thu Dec 10, 2015 8:15 pm

For the sake of clarification, a loop will always run until one of two things happens: its terminating condition becomes true, or the break action is called from within. Until a loop has terminated, nothing else will run, so it's generally a bad idea to wait on external input to terminate a loop.
Moderator
B
113
S
41
G
20
Posts: 1,586
Reputation: 19,116


Return to How do I....?

Who is online

Users browsing this forum: brunopalermo, cb130felix, Kermad, Lancifer, tarek2 and 7 guests