How do I use "loopindex" with "wait" in a for loop

0 favourites
  • 5 posts
From the Asset Store
SynthWave Loop Pack includes 68 seamless loops, founded on 11 original melodies.
  • I understand to get an event to trigger in a for loop with "wait" you have to multiply the time between each event by the loop index so;

    onStart

    forLoop 1-4 -> wait loopindex * 1

    And it does trigger once every second for four seconds. But the problem is that "loopindex" is coming up as -1 instead of the actual loop index. And that is causing me problems. Does anyone know a way around this?

    Here is a link to display what I am running into.

    https://dl.dropboxusercontent.com/u/820 ... est.caproj

    Many thanks!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • That is a bit of a weird way to do this.

    When you make a 'for' loop. The system stays in that loop, till its done. Adding a wait will cause you many problems.

    Especialy when you add to the wait time.

    May i suggest to do this in a differend way. Use the timer behaviour on any object.

    Start a continue running timer with tag "loop".

    Then 'on timer "loop"' do your stuff. Add 1 to some local variable to have a loopindex.

    When that loop index has some value, stop the timer.

    If you create objects in that loop, only create them in the on timer event.

    Use a 'on creation' to do stuff with them. Because 'on creation' selects the right object after it is created.

  • Interesting. I've never used the timer behavior before. Specifically what I'm doing is;

    When the player hits spacebar, the hero sprite will fire projectiles. The number of projectiles, how much damage they do, the angle they travel, etc., is all pulled from a database.

    I'm trying to get the projectiles to be able to leave at slightly different times (if there is more than one projectile being fired) so they are clustered differently. I suppose I'd put the "timer" behavior on the "keyboard" and on space bar trigger the loop regularly from that?

    I'll give it a try. Thank you!

  • Then the suggestion i gave you is a good solution. With as less as a performance drop as possible.

    I dont think you can attach a behaviour to the keyboard object type.

    Instead, attach it to the hero. Because. Well the 'on timer' will also set the hero selected that way.

    Easy to fire from predefined imagepoints on the hero, or from whatever position, i suppose the position from where the firing is happening is linked somehow to the position of the hero.

    That is another huge plus of the timer behaviour. No probs with picking.

  • Great! I appreciate the help.

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