How do I understand FOR each.

Get help using Construct 2

Post » Sat Jul 05, 2014 1:27 pm

i use it a lot, especially when i have multiple instance of an ennemy.
i often need it to prevent them to all act the same.

BUT i dont really understand how it works.
is there some guide to explain how to use it properly ?
because its often that it dont work the way i planned and i have to do it all over again.

does the position of the for each condition is important ? should it be placed first or last ?

Posts: 104
Reputation: 1,761

Post » Sat Jul 05, 2014 5:35 pm

Wrote out a long description but it just makes it more confusing. I'll try to do a short and clear answer.

Say you have 20 objects, and you 'pick' 10 of them due to some condition, e.g Pick all objects who's X coord < 100. The events only run once per frame, and anything that applies to this type of object will apply to ALL PICKED objects, ONCE. So for example, say you wanted to change their X coord to 200. You just need to say 'Set X to 200' and it would apply to all of the 10 objects you just picked. No for-each needed.

When you DO need a for-each is if, for some reason, you want to run the events once for each picked object. So in our example above, we have 10 picked objects, and you want to run the events 10 times, for example, you want to create a text object for each picked object. You can't just put 'Create text object' in your events as that would just create one object (the event only runs once usually). So you do a for-each, run it 10 times, create a text object inside the loop and you're now working with an individual object on each loop pass.

There are probably better and simpler explanations but hopefully it helps a bit.
Posts: 446
Reputation: 5,633

Post » Sat Jul 05, 2014 6:02 pm

Posts: 3,006
Reputation: 27,744

Return to How do I....?

Who is online

Users browsing this forum: FlyingRam and 9 guests