Question about creating objects within a for loop

Get help using Construct 2

Post » Thu Jan 17, 2013 5:20 am

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.

Thanks in advance!
Posts: 2
Reputation: 254

Post » Thu Jan 17, 2013 1:55 pm

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.vee412013-01-17 13:57:03
Posts: 756
Reputation: 7,192

Post » Thu Jan 17, 2013 4:10 pm

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.Phyvo2013-01-17 16:12:03
Posts: 40
Reputation: 917

Post » Fri Jan 18, 2013 12:42 am

That seems to have fixed it, thanks again!
Posts: 2
Reputation: 254

Return to How do I....?

Who is online

Users browsing this forum: emoaeden, yurinkab, zenox98 and 17 guests