For Loops & loopindex()

0 favourites
  • 5 posts
From the Asset Store
40 ambient sound loops. A wide selection of looping ambient sounds for different locations.
  • 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

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

  • Try Construct 3

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

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

  • 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?

  • 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?

    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.

  • Ah nice thx

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