Loopindex issue

0 favourites
  • 6 posts
  • 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 <img src="smileys/smiley1.gif" border="0" align="middle" />

    dl.dropbox.com/u/94794009/Contruct_examples/loopindex_issue.capx

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

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

    I really just wanted to know why the first example doesn't work?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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.

  • 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.

  • 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.

  • 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.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)