The For Each Object may not work in Flash. As this example here shows:
http://www.clickteam.com/epicenter/ubbthreads.php?ubb=showflat&Number=211616&Searchpa ge=2&Main=28892&Words=Tiles&Search=true#Post211616
The For Each Object may not work in Flash. As this example here shows:
http://www.clickteam.com/epicenter/ubbthreads.php?ubb=showflat&Number=211616&Searchpa ge=2&Main=28892&Words=Tiles&Search=true#Post211616




If for each actually doesnt work or doesnt work the same way in flash this is important to fix, because optimizing is very important for flash!
Along the same lines, what about lava mobile, does for each work in java mobile runtime?
For Each does have limitations compared to Fast Loops. Mainly dealing with maintaining object selection with nested loops. But in general, it does the job.
Hm, as my example shows, it does not do the job![]()


The foreach object is very powerful, very buggy. Flash is one of those bugs atm, but dont hold your breath on it being fixed
I just have no real knowledge of ForEach and I can't really find any tutorials or anything on it... From what I attempted, it worked for detecting the falling block landing on the obstacle block, but not for landing on instances of other falling blocks...Originally Posted by Dynasoft
I'm not one to usually ask for examples, but if someone wants to convert the example I posted earlier in this thread into ForEach instead of fastloops, I would definitely appreciate it.
If not, I'd appreciate other examples or a good tutorial/explanation on ForEach.
I know you say they "basically work the same" but that's different than "they work the same". =P So I need to know the differences.
Which is another reason I'm not using ForEach... In this scenario I'd rather have a working (although quite limited) game in Flash, instead of no game at all.Originally Posted by Pixelthief
Though if ForEach could really improve performance in my exe build, I would definitely be willing to change it and just use fastloops for the Flash demo.
From what I've been able to gather, fastloops work great, they just eat up performance. ForEach doesn't eat up performance, but it's buggy/doesn't work with Flash, and I don't know how to use it.
So it's pretty clear that I've gotta stick with fastloops unless I managed to figure out ForEach, and it gets some bug fixes.


If you're still trying to use it in flash, examples wouldn't do much good. Outside of flash, its pretty simple. When you run a loop in foreach, it will run that line of code N times for the N objects in the group you are running on. Each of those times, it will specify a single copy of that object and apply the action to him. If the actions operate mutually exclusive of each other, the order won't matter, but otherwise it is either the order you added them to the group or the order the objects were created.
You can either start ForEach loops for an object, or start them for a group as defined in the foreach object. You can use groups by adding objects using its "Add object to group" function- by specifying the objects using conditions in your code, you can add say half of the instances of one object and half the instances of another. You can specify which instances of which objects you add to a group, which works much like a qualifier, except made at runtime. Make sure after running your loop that you remove all instances of all objects from that group list, if theres any chance they could be destroyed/etc
For the conditions, you can either have a condition execute on the loop, or on the loop for a specific type of object. Any condition that triggers for the loop will trigger once for every single loop it does- N loops triggers that condition N times, and you can apply any actions you want without affecting the object scope list (ie you can operate on the set of all objects that you'd normally specify via the next condition). The next condition, "On fast loop for object" will trigger once per each instance of that object in the current group, and each time it reduces the object scope to just one instance of that object. So it might run N times for N objects, but each time only a single instance of the object is scoped.
Does this mean it's only looking at one single copy of the object at any given time? Is this why I can't get an instance to collide with another instance? That's really the issue I'm having at the moment.Originally Posted by Pixelthief
If it's isolating one of the instances, it's not paying any attention to the hundreds of other instances, meaning it's not going to detect them at all... or am I mistaken?


That would be correct. When it lowers the scope to a single instance of an object, it is more difficult to do collisions between instances of the same object. What you COULD do instead is just have a secondary 'detector object'.
So you isolate the instance of the object, position the detector on top of that object, and then compare the detector to the larger set of objects for collisions. It would look like this:
*(ON CONDITION)
= Start ForEach loop "Test" for "Object"
*On ForEach Loop "Test" for "Object"
= Set Position of "Detector" to Position of "Object"
= Set "Detector" Flag 1 Off
*On ForEach Loop "Test"
+"Detector" is overlapping "Object"
= Set Flag 1 of "Detector" On
= (DO ACTIONS SPECIFIC TO OVERLAPPED OBJECTS)
*On ForEach Loop "Test"
+Flag 1 of "Detector" is On
= (DO ACTIONS FOR ALL OBJECTS)
*On ForEach Loop "Test" for "Object"
+Flag 1 of "Detector" is On
= (DO ACTIONS SPECIFIC TO THE CURRENT OBJECT)
So in this case, you have the group of all objects (ALL OBJECTS), the single instance of an object that it is iterating through one at a time (CURRENT OBJECT) and the objects of the same class that the current object is overlapping, including the current object (OVERLAPPED OBJECTS).
So lets say you wanted to do something simple. For each of those actions, you add 10 to the value A of each of those objects- for the specified object, for the overlapped objects including specified again, and all objects, including all those.
So if object A overlaps object B, but not object C
First the loop iterates through A. It sees A overlapping B, therefore so it adds 10 to the set of both objects first: A = 10, B = 10, C = 0.
Then it adds 10 to all objects: A = 20, B = 20, C = 10.
Then it adds 10 to just the specified object: A = 30, B = 20, C = 10
But now when it iterates through B, it also sees B overlapping A, just as it saw A overlapping B. So it repeats the above process, and you get: A = 50, B = 50, C = 20.
Now it iterates through C, and sees no collision, so nothing increases.
You have to think about which objects you want to scope and what actions you want to apply to them for each function you are doing. It really matters exactly what you are trying to accomplish. Are you trying to destroy two colliding objects? Are you trying to destroy only one of the two, and if so, which one do you choose? Do you want to do an action to all objects based on a value from the colliding object(s)? If so, you'd need to store it outside of the referenced object- put it in a neutral 3rd party object like the detector.