For Loops & loopindex()

Get help using Construct 2

Post » Mon Jan 28, 2013 5:12 pm

Hi guys and gals,

I'm having trouble with using a For loop, my for loop never seems to terminate and was hoping someone could show me what I've done wrong.

I've attached an example. I got it working but it's messy and uses variables to count the index (without loopindex).

If you disable the first loop and enable the second then you will see what I mean.

Thanks,

ShabbyCat

http://dl.dropbox.com/u/11384284/ForLoop.capx

B
15
S
1
G
3
Posts: 47
Reputation: 1,912

Post » Mon Jan 28, 2013 8:09 pm

Because your for loop is running every tick. You should set it to run on start of layout or some other condition so it's not continuously spawning shield sprites.
B
54
S
28
G
18
Posts: 1,520
Reputation: 24,990

Post » Tue Jan 29, 2013 3:15 am

Oh right, OK thanks I didn't realize that it would run every tick unless I told it to run every tick, but it makes sense otherwise you'd only be able to push left once to go left and never go left again.

So anything told to run at the start of the layout will just run once?
And what happens if you need a for loop that terminates when a condition is met mid game?
B
15
S
1
G
3
Posts: 47
Reputation: 1,912

Post » Tue Jan 29, 2013 6:51 am

[QUOTE=ShabbyCat] Oh right, OK thanks I didn't realize that it would run every tick unless I told it to run every tick, but it makes sense otherwise you'd only be able to push left once to go left and never go left again.

So anything told to run at the start of the layout will just run once?
And what happens if you need a for loop that terminates when a condition is met mid game?[/QUOTE]

You'll just need to create proper triggers that state when the loop should be enabled and when disabled. You could for example do it like this:

global variable loopEnabled = 1

loopEnabled = 1
for 0 .. n
do stuff

Now, if you change 1 to anything else the loop will not run anymore.
B
24
S
8
G
7
Posts: 756
Reputation: 7,192

Post » Tue Jan 29, 2013 7:00 am

Ah nice thx
B
15
S
1
G
3
Posts: 47
Reputation: 1,912


Return to How do I....?

Who is online

Users browsing this forum: CavalierBubble, imnotspecial, tomi71, totoe, Yahoo [Bot] and 23 guests