Trouble with "For each" Loop

Get help using Construct 2

Post » Mon Sep 24, 2012 3:48 pm

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
B
12
S
2
Posts: 39
Reputation: 1,069

Post » Mon Sep 24, 2012 4:36 pm

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.
Don't see the fnords and they won't eat you!
B
75
S
16
G
12
Posts: 322
Reputation: 11,608

Post » Tue Sep 25, 2012 11:27 am

Thanks heaps Wastrel, Problem solved :)
It makes perfect sense too!

And thanks for the tip on saving files, will remember this for next time.
B
12
S
2
Posts: 39
Reputation: 1,069


Return to How do I....?

Who is online

Users browsing this forum: Paradox, Yahoo [Bot] and 2 guests