# For loop problem

Get help using Construct 2

### » Thu Apr 25, 2013 4:58 am

I'm making a game(it's still an idea) its kinda like a dragon/snake with turrets for every 3 nodes in his body, and i cannot find the logic to start... i guessed i should start with the for loop although i cant specify "for every 3 nodes create 1 turret for the 3rd node"... help?
thanks again
B
8
S
2
G
3
Posts: 36
Reputation: 2,286

### » Thu Apr 25, 2013 5:50 am

sounds cool,

there is an expression called 'loopindex' which returns the index of the current loop.

Indexes begin on zero.. so the first index of the loop is 0, the second is 1 and the third is 2 etc

so to do something different on the third repetition of a loop, you can do:

+system, compare two values | loopindex is equal to 2
->create turret etc

to do this thing *every* three repetitions, (starting on the first) you can use the % operator:

+system, compare two values | loopindex%3 is equal to 0
->create turret etc

the '%3' makes it go back to zero on every multiple of 3

so for example '107 % 100' will return 7

and '541 % 100' will return 41

and '6 % 3' will return 0

also if you dont want it starting on the first, you can offset it like '(loopindex+1)%3'
B
28
S
8
G
1
Posts: 469
Reputation: 4,683

### » Thu Apr 25, 2013 5:55 am

awesome!, imma test it right away thanks! :)
B
8
S
2
G
3
Posts: 36
Reputation: 2,286