0 Favourites

Trouble with "For each" Loop

  • 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

  • Construct 3

    Buy Construct 3

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

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

  • 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)
Similar Topics Posts Views Last Post
Unread hot topic Locked topic
275 18,711
Tom's avatar
Tom Construct Team Founder
Unread hot topic
175 32,628
clifton11221's avatar
clifton11221
Unread hot topic
57 53,161
weilies's avatar
weilies