Trouble with "For each" Loop

0 favourites
  • 3 posts
From the Asset Store
SynthWave Loop Pack includes 68 seamless loops, founded on 11 original melodies.
  • Hey guys,

    I'm new to construct after years of playing around with mmf2

    I'm having trouble with a For each loop.

    The idea is that after dragging an object, it returns to it's original position. I have set up a for "For each" loop that stores the objects coordinates at the start of the layout.

    It seems that the loop is repeatedly updating the objects coordinates...

    Isn't a "For each" loop only supposed to run once?

    I'm not stranger to loops, surely I've overlooked something simple!!!

    (The problem is in layout 3, everything else is just stuff I've been exploring :) )

    Thanks in advance!

    Luke

    p.s. Excited to join the community!

    My Drag and Drop Project

  • Luke,

    First, welcome to the community and to Construct 2!

    Second, for future reference, you can Save As... to a single capx file, which makes it a lot easier to share projects. That way you don't have to zip the files.

    Third, regarding the main issue, you have to remember that C2 is event-based, and that the game loop runs through all events in order, from the top of the sheet to the bottom. Thus, your For Each loop is executing every tick of the game loop.

    To fix this, create a System -> On Start Of Layout condition, and move your For Each loop block underneath it, as an indented sub-event. Then you should see the results you are looking for.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks heaps Wastrel, Problem solved :)

    It makes perfect sense too!

    And thanks for the tip on saving files, will remember this for next time.

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