r236 repeat loop with wait loopindex bug

Bugs will be moved here once resolved.

Post » Sat Oct 15, 2016 2:45 pm

Problem Description
loopindex returns -1 for repeat loop when using wait

Attach a Capx
http://badpadgame.com/loopindexBug.capx

Description of Capx
Runs a x10 repeat loop with waiting and loopindex printing

Steps to Reproduce Bug
  • Click button
  • See output in text object

Observed Result
loopindex printed before the wait action returns correct value, loopindex after wait action returns -1

Expected Result
return correct loopindex.

Affected Browsers
  • Chrome: (YES)
  • FireFox: (YES)
  • Internet Explorer: (YES)

Operating System and Service Pack
Windows 10

Construct 2 Version ID
r236
Image
B
78
S
29
G
12
Posts: 515
Reputation: 12,559

Post » Sat Oct 15, 2016 3:34 pm

No bug. The expression loopindex() has only meaning in the scope of the event containing loop.
Once you go outside the loop, loopindex() has totaly no meaning no more.

The wait postpones the actions. So, those actions are executed outside the loop, they are even executed in some ticks after the loop ran.

Something close to this. You are moving (top - down) from the living room to the basement. You have the remote control of the TV in your hand. In the living room you must change channels for 10 times. No problem. Now comes the wait. Change channels 10 times over 5 minutes(*some time). By that time you are in the basement, outside reach from the TV. Out of scope.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Sat Oct 15, 2016 3:40 pm

Yeah but what if the t.v follows you down? :)

I got it, I'll use an extra var.
Image
B
78
S
29
G
12
Posts: 515
Reputation: 12,559

Post » Sun Oct 16, 2016 8:12 pm

Then, Coronation Street caught you.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Tue Oct 18, 2016 11:40 am

Closing as not a bug: @99Instances2Go is right, by the time the action after the wait runs, the loop has ended.
Scirra Founder
B
397
S
236
G
88
Posts: 24,420
Reputation: 194,549


Return to Closed bugs

Who is online

Users browsing this forum: No registered users and 0 guests