Question about creating objects within a for loop

0 favourites
  • 4 posts
From the Asset Store
SynthWave Loop Pack
$3.50 USD
50% off
SynthWave Loop Pack includes 68 seamless loops, founded on 11 original melodies.
  • Hi all, downloaded Construct 2 a few days ago for a school project, been fun so far. However, I seem to be having trouble with the loop syntax.

    I want the number of enemies in the wave to increase by one every time the wave repeats. No matter what I do, it seems the body of the loop only executes once. I've set the lower bound of the for loop at 0, and the upper bound at 10 for testing purposes, but it continues to only execute once.

    Here's a link to what I have so far, my issue is on line 28 of event sheet 1.

    dropbox.com/sh/3lwfa1t243z6ai2/v7RSSZ2IQE

    Thanks in advance!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Event sheet is pretty hard to understand, but from what I gathered you are spawning the 10 enemies pretty much on top of each other. Is your intention to spawn 1 of each enemy in the first 'wave', 2 of each in second and so on?

    EDIT: It's also a good idea to save projects as single .capx file instead of sharing the whole project folder.

  • Your loop is actually running 11 times (because there are 11 numbers in a list of numbers from 0 to 10). You just can't see it because you're spawning all the enemies on top of each other instantly as Vee said. To better see what your setup does add a "wait loopindex*0.1 seconds" action to your loop and put "add 1 to current enemy count" immediately before the wait and your "create object one" action immediately after the wait.

    One note about the wait function in loops: wait operates in parallel, that is, if you had "wait 0.1 seconds" in a loop your loop would just create all 11 objects 0.1 seconds later. In order to have each repeat wait a different time you need the loopindex variable.

  • That seems to have fixed it, thanks again!

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