For loop problem

  • 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

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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'

  • awesome!, imma test it right away thanks! :)

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