How do I insert a "wait" event into a loop?

From the Asset Store
SynthWave Loop Pack includes 68 seamless loops, founded on 11 original melodies. For use in game and custom works.
  • I am trying to loop over the Y of an arrays and if an array field contains the string "delay", it should wait an X amount of seconds and then continue with the loop. This seems to be harder than imagined, because loops and for each's ignore the wait event.

    I haven't yet since Sunday managed to find a way that works at all. Some of the suggested ways in the forums also don't really do the job.

    I've tried to just put a "wait" event in a loop, but that doesn't work per the docs. Tried using a wait 0.01 * loopindex, which doesn't work. Tried running using async functions that contain a wait in the loop. Also have tried many other detailed ways or workarounds but neither was a success...

    Made a nicely documented project for it:

    drive.google.com/file/d/1PBpbEjx1gvEZkjLNRjSO21_zjsGRV2xP/view

    Any help would be much appreciated.

    Tagged:

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Just a little information about a loop that may help explain why this is not the correct way to do what you want:

    Loops in construct are intended to complete in a single tick. Introducing a delay the way you are trying would completely pause your game until the delay is over because no other processes could complete. Instead, a delay in a loop will just delay between actions that happen within each iteration of the loop.

    What you need to do is, record which position of the array you are on when you hit the delay and, exit the loop. Then, after the delay time is complete, start the loop again at the index you recorded. This is called an iterator.

  • Actually tried that approach, but must've done it terribly wrong. Revisited that approach now with the demo project and yeah, works perfectly now. Thank you very much InDWrekt, appreciate it!!

    I'll leave the working version permanently on my drive if anyone else ever needs it:

    https://drive.google.com/file/d/1PBpbEjx1gvEZkjLNRjSO21_zjsGRV2xP/view?usp=sharing

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