Loopindex issue

Get help using Construct 2

Post » Sun Jan 27, 2013 2:31 am

I am having a strange problem using the loopindex variable in conjunction with the wait command. I get an error every time I use it, but am unsure if it is a bug or limitation?

In the example capx file, when you hit spacebar you start to see red squares created randomly...no problem here, and it is using the loopindex variable combined with the wait command for the time stagger.

Now when you hit shift it should create blue squares in a row using the loopindex to control the x placement, and also to stagger then creation via the wait command. I get a javascript error each time in Chrome.

Interestingly , if I disable the wait command in this function it runs, but of course without a time stagger.

Not sure what is going wrong here? Any help would be much appreciated

http://dl.dropbox.com/u/94794009/Contruct_examples/loopindex_issue.capx
B
11
S
2
G
1
Posts: 108
Reputation: 1,899

Post » Sun Jan 27, 2013 2:40 am

Btw, I should add that I know how to get around this issue by using a global variable:

http://dl.dropbox.com/u/94794009/Contruct_examples/loopindex_issue_resolve.capx

I really just wanted to know why the first example doesn't work?
B
11
S
2
G
1
Posts: 108
Reputation: 1,899

Post » Sun Jan 27, 2013 2:47 am

You can only use loopindex when you're inside a loop. After the wait, when the create object action runs, it's looking for loopindex which doesn't exist because the loop has finished.
B
54
S
28
G
18
Posts: 1,520
Reputation: 25,020

Post » Sun Jan 27, 2013 3:06 am

Ok, thanks for the quick reply ramones! I figured it was something like this and am just trying to work out some of Construct's quirks.
B
11
S
2
G
1
Posts: 108
Reputation: 1,899

Post » Sun Jan 27, 2013 3:12 am

Yeah it uses the value of the variable when the action actually runs, not the value it was when you called the 'wait' action. Like in your fixed example with the global - if you changed that global variable in another event before the wait time was up, it would screw it up.
B
54
S
28
G
18
Posts: 1,520
Reputation: 25,020

Post » Sun Jan 27, 2013 3:37 am

That makes sense. Is there a better way of doing this? In general, I am finding triggered/timed animation the trickiest thing to do in Construct.
B
11
S
2
G
1
Posts: 108
Reputation: 1,899


Return to How do I....?

Who is online

Users browsing this forum: totoe and 21 guests