For Loop and wait

Get help using Construct 2

Post » Mon Apr 08, 2013 8:14 am

Why this is not working??

For "slowDownLoop" from 1 to 5
     txtBox set text to "LoopIndex: " & LoopIndex("slowDownLoop")
     System wait 1.0 seconds


Every time the loop runs it sets the txtBox to "5" from the beguining, I would like to see the counter increment every second but its not happening that way.

Thank you
Image
B
14
S
4
G
4
Posts: 133
Reputation: 3,150

Post » Mon Apr 08, 2013 8:21 am

Seems that each loop cycle is excecuted one after another not respecting the wait, so I tried this:


For "slowDownLoop" from 1 to 5
     System wait 1.0 * LoopIndex("slowDownLoop") seconds
     txtBox set text to "LoopIndex: " & LoopIndex("slowDownLoop")


but by the time the first second has passed the Loop has already finished running and the LoopIndex is already "5"

Cant figure this out without using a helper variable.
Image
B
14
S
4
G
4
Posts: 133
Reputation: 3,150

Post » Mon Apr 08, 2013 8:40 am

The whole loop is executed in one tick, you can use search to find some discussions about it :)

After the wait event the loop is not really executing anymore, so you cannot refer to loopIndex anymore. You could do it like this:

variable = 0

for 0 .. 10
.. wait loopIndex seconds
.. add 1 to variable
.. set text

Why not use 'every 1 seconds' event to set your text rather than a loop?
B
24
S
8
G
7
Posts: 756
Reputation: 7,192


Return to How do I....?

Who is online

Users browsing this forum: Yahoo [Bot] and 28 guests