"For Each" seems to not work when referring to object groups

Examples:

This event is supposed to make each object in the rangedenemies group shoot projectiles towards the camera position. At any given time, only one ranged enemy on screen will be attacking.

Here’s another example: This event is supposed to make all objects of the group enemies collide with each other. It only works on identical objects, all other objects pass through.

I noticed this on my previous game as well.

The repeat timer is a single timer not an object timer. It will only allow 1 object to fire every x seconds. Since the for each object uses the same pick list order, the same object will get the 1st chance to fire preventing the other objects from getting a chance to fire. You can use an object timer or the fire behavior which has a built-in cool down.

edit: For clarity, the first object in the filtered pick list would fire, meaning if 3 objects were in range only the oldest object would fire since the object list is sorted in the order in which the objects were created. The timer also resets as soon as it’s checked.

The 2nd example, separate object doesn’t need any conditions. It does its own collision testing. But as is the for each object event only picks 1 object at a time. So, it’s trying to separate it from itself.

3 Likes

Dont know about the Enemies and camera issue, but the separate objects one i had some experience with that.

I thought i had to run it trough a For Each to separate all enemies doing exactly what you did with the separate Enemies from Enemies, no dice, didnt work at all.

So then i tried not doing a For Each, just using a normal event and it kinda worked, it wasent perfect because i think its just awkward logic, since how do you define which instance gets moved and which dosent… thats how i thought about it at least, but it sorta works.

…or maybe it really is just a bug :stuck_out_tongue:

EDIT: Considering what Keith said, i guess it really is how it works and not a bug, Keith seems to really know his stuff so im going with that :slight_smile:

1 Like

Thank you for the info, Keith.

I didn’t mention in my original post but the second event I showed also doesn’t work without the “for each” added. It will still only detect collisions when like meets like. For example, if I have sprites A, B, and C in the enemies group, A will collide with each other but not with B and C and likewise for the others.

Since unlike objects in my object group “enemies” won’t collide with each other, I have considered making a collision sprite object and make it collide with itself. Do you think that would work @Keith_1357 ?

I’ve never had much success with keeping objects separated in a natural looking way. It’s slightly easier to try to keep them from building up too much in one spot either through timing or spawning from different directions.

I’m not the person to ask for keeping objects apart. I wish separate objects worked the same for groups as for the same object.

Otherwise, object A pushes B into C and C pushes B into A and then A pushes C into B. It’s all too chaotic for me. Other times they just clump up and push each other like they’re one object. It just seems unnatural.

There must be a way to create more intelligent AI but I’m not aware of it.