How do I understand FOR each.

0 favourites
  • 3 posts
  • 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 ?


  • 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.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)