I posted a .cap, that till some level demonstrates what you seek, in the uploads section. (help3 page 2)
The presents of "for each" confused me for long time. Long time i tried 'loops' for picking objects. Wich is the wrong aproach.
Forget "for each ", its usaly not usable.
1/ Loops u need
to repeat an ACTION ... (x times) ... till the condition of the loop is met. You can use the loopcounter to alter variables in the loop.
Like building a row of objects spacing 20 pixels, 10 objects in total
for loop "ThisLoop" 1 to 10
_________set objects x to .X + ThisLoops' counter * 20
2/ Pickin objects you do with events.
Most events that pick an object, pick a group of objects. Pick specifiek object you do with an event combined with a condition. The condion works as a filter.
You can also only use a condition.
Concrete:
If u have 2000 of the same instances on your screen
an event like
Sprite: Value 'PrivateV' Equal to 1
Will set all Instances with private variable 'PrivateV' Equal to 1 as picked ..
Every Action with this event will only target the picked Instances
How u do that ?
Add an event ...
pick the object
click on the tab private variables (on bottom)
click on compare private variable
pick ur private variable
give the value u want to be compared.
So un ur case ..
the event
Enemy: Value 'walk' Equal to 1
Will "pick" out all Instances called "enemy" only those that have the private variable "walk" set to 1, and will pass "the picked objects" to the actions combined to the event.
Those private variables you can set when
A/bringin the object into the layout in the Layout editor.
B/When u create an object in an action, the created object is "picked". Create u do in an action. So every next line u put in the same action block, targets the just created object. (Its picked)
Including setting private variables and the use of "self" in expressions.
C/And ofcourse u can set a private variable in every action anywhere, by plain targeting (pick) the object and set a private variable. But this u know.
So in general. Think out of loops for picking objects. Thats the wrong aproach.
Pick Objects with events. Most events return a group of objects. And filter out the object you need by conditons. Most Events pick objects by default. By instance, the collision detection will set all involved objects as "picked". When u use an action after this, the action will target the 'picked objects', in this case those that are involved in the collision
You can use Condtions alone too.
It took me long time to understand this, its not in the docs, and ne one explained me.
Most poeple who onces programmed in another object-based language, think in LOOPS and LOOPS and LOOPS.
Ashley made the looops we need to "pick objects' buildin, fast and automaticaly, all you need to do is "filter" the objects u need by conditions. Usaly based on comparing to a private variable.
Try to avoid using GLobal Variables. THey are slow, and are not as accesable and flexible as Private variables. Even prefer to make a Control object, that you only use for holding variables as private variables, over using global variables.
Also Use the Family option to make groups of "clones" or differend "instances". Events targeting a family sets the whole group of objects in the family to "picked".
Al u need is a condition that filters out the objects you need.
Like
Always
event: Sprite "red balloons"
____conditon: "red Balloons" smaller then 5
_________________________________action: destroy
Hope this helped you.
j0h