For Loop!?

0 favourites
  • 7 posts
From the Asset Store
SynthWave Loop Pack includes 68 seamless loops, founded on 11 original melodies.
  • Could someone explain what this for loop is doing when executed in construct?

    sounds a silly question but its doing strange things.

    Cant seem to get predictable behavior from it. All I want to do is

    when something happens

    from 1 to variablestorednumber

    every 1 second

    ---------------------------- do something

    if i repeat it once for an action what i get is the the loop seems to just jump to the end, no matter how i play around with it.

    And if i dont do that it just keeps counting up.

    Cant seem to find a working example of the for loop about.

  • Loops are only executed in one tick.

    For what you are trying to do try some variables like:

    +compare variable variablestorednumber is >0

    +every n seconds, do fo, subtract 1 from variablestorednumber

  • Yeah have it working that way too, but was trying to add in some other checks and thought the for loop would allow me to get those things working easier. Clearly not

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • A For loop will go from a starting value to its end value with an increment of 1 each time it loops.

    So:

    For 0 to 5

    (Will start at 0 and end at 5)

    So 0,1,2,3,4,5

    You can get the current index of a loop by using loopindex. This also means as C2 encounters a loop it will finish it before continuing. And guess that's why you think it jumps to the end, but in fact its running 5 times through the loop. So if you at the end of the loop have something that would be an end, then that is what it will be.

    But when the loopindex is = 5 in the above example then the loop is done and C2 will continue with whatever.

    In your example you would normally do like this:

    Every 1 second

    For 1 to Variablestorenumber

    ...do something

    (Which means that every 1 sec you run a loop starting at 1 and end at "Variablestorenumber")

    So its predictable in the sense that you might know the starting value and the end value, or at least based on some calculations know them and you know that it increment by 1 each time.

  • Forgot I did try repeat once, but still not going to work with the FOR.

    What i was trying to do is execute one loop, wait a few seconds then move onto the next loop.

    Not have all the loops running at the same time but in sequence.

  • Ah resolved it thanks

  • BinaryPanda - How do you resolve this?

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