How do I make this for loop work?

Get help using Construct 2

Post » Tue Jun 02, 2015 5:50 pm

Hello,

another event activates the group asdf
Image

But this very simple loop doesnt do what I want lol. I want ever 0.5 seconds to spawn an object at x=0,100,200,300 and also increase the size by 50 everytime but it doesnt work. It's like the loopindex stays 0 all the time because it only creates 1 (or more objects and puts them all at the same spot).

Ive dont stuff like this 1000 times already which is why I am so confused. Can someone help? thanks
B
12
S
3
Posts: 211
Reputation: 1,477

Post » Tue Jun 02, 2015 6:27 pm

So you really want

local number blabla=1
system repeat 10 times
> system wait 0.5 seconds
> system create object sprite_obstacle at (blabla*100, 1961)
>sprite_obstacle set width to 50*blabla
> system add 1 to blabla
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Fri Jun 05, 2015 4:28 pm

LittleStain wrote:So you really want

local number blabla=1
system repeat 10 times
> system wait 0.5 seconds
> system create object sprite_obstacle at (blabla*100, 1961)
>sprite_obstacle set width to 50*blabla
> system add 1 to blabla


Thank you but this doesnt work at all. It doesn't increase the width. It somehow works if I replace the wait system 0.5 seconds by wait system 0.5 * loopindex. But the width stays the same.

/e: well it all works if I use a global variable instead of a local one..very weird
B
12
S
3
Posts: 211
Reputation: 1,477

Post » Fri Jun 05, 2015 7:30 pm

I'm not sure this is a good way of doing this. Would you be better off setting a repeating timer and having a counter of the number of times it has fired, then kill the timer when you have done 10 ? Like this ?

http://www.studio2.org.uk/c2/Spawning.capx
My tutorial through development blog is at http://myconstruct2dev.blogspot.co.uk/
B
12
S
3
Posts: 221
Reputation: 1,328


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 2 guests