How to count number of objects at a position/doing action

How do I count the number of object at a position or displaying an action (movement or animation for example)?

Basically I want an variable to increase every time an object reaches a position (or I could check its force/animation if that is easier). As all the objects are spawns of the same thing they are all called “A”.

So I have tried increasing variable by +1 everytime “A” reaches the position but it increases the number infinity once the first one is there. If I say Trigger Once, it only recognises the first object and not the other 3 as they reach that position.

I am sure I am missing something simple but it is alluding me :confused:

Just use the expression Count(MyObject) that returns the number of instances of the object MyObject that are currently concerned by the event. With the use of the conditions to test if the object reached a point, you can have the number of objects that reached the point.

Okay, that sounds promising. I remember seeing the compare expressions but not one… so would this work (where A is the name of the object):

The Y position of Count(A) is = 200

Is that what you mean?

*wait that wont work… haha. Okay so confused

Am I aiming for something like this?

Do you really need a variable (why an object’s variable by the way ?) ?

You could do a “For each” event, within which you check the Y position of every instance and add 1 to the variable if it’s high enough. You would then need a “no condition” event that resets the counter variable to zero to stop the number going up every frame. It would have to come after the conditional event that checks the value of the counter. Maybe something like:

Event 11
For each object Bee, repeat:
The Y position of Bee = 200 | Do +1 to variable InsectPositionCount

Event 12
Variable InsectPositionCount is =4 | Do something

Event 13
No conditions | Do =0 to variable InsectPositionCount

Just would like to add, from my experience in GDevelop always better to check a range of value when you check position of an object.
So instead of checking

Y = 200 

I recommend to check

Y >= 200

or

Y > 195 and Y  <  205

Simply because when you move an object to position 200, it is unlikely to stop exactly at 200 but maybe at 198 or 201.
Depends on what forces and actions you are using to move and stop the object, sometime the difference can be as big as 20 pixels so just to be sure, don’t expect it to be exactly at 200.