Interaction between multiple instances of the same object

Hi folks,
I encountered a problem which is driving me nuts.
In my Sakawochi game I have multiple instances of my seahorse object which should interact with each other.
In particular, I want to move one specific instance towards a random other instance (excluding the aforementioned one) under the condition that both are grown up (size variable = 1.0) and a certain time has passed (mating_timestamp <= current_timestamp).
This thing is giving me a headache. I already tried to

[code]- Pick all objects seahorse

  • The text of variable ID of seahorse != seahorse.VariableString(ID) → object count returns 0[/code]
    I also tried saving the ID of the seahorse willing to mate into a temporary variable and looping through all seahorse instances to match the first one with a different ID but also without success.
    When I move seahorse to seahorse my seahorses just move off screen eventhough there is no other seahorse to move to in that direction. I guess they are just moving into some direction trying to reach its own position.

Does anyone have a clue about how to handle interaction between instances of the same object in a manageable manner without going crazy?

EDIT:
To simplify the question, lets say I have multiple instances of an object and I know the ID property of two of them. What would I have to do to move instance-1 towards instance-2?
I tried “Move seahorse to seahorse with a force of x” which doesn’t work.

It’s a known limitation of GD, as GD manages the objects lists for you you can’t do in-list operations, as moving two instances in the same list (same object/object group) to each other’s position.

And yes, as you have deducted you need scene variables to store values temporally.
Working with your EDIT general example, the idea would be:

  1. Pick Seahorse with ID = 2
  2. Save Seahorse position in variables X, Y
  3. Pick Seahorse with ID = 1
  4. Move to position of variables X, Y

Also, take into account that object picking affects the current event and its sub-events only, so you can do things like:

// This event picks the first Seahorse
Conditions: Variable "ID" of Seahorse is = 1
Actions: No actions

        // This sub-event picks every instance and then the second Seahorse, changes the pick for this event and its sub-events only
        Conditions: Take into account every Seahorse
                    Variable "ID" of Seahorse is = 2
        Actions: Do = Seahorse.X() to the variable "X"
                 Do = Seahorse.Y() to the variable "Y"

                // Sub-sub-event, still referring to the second Seahorse
                Conditions: No conditions
                Actions: Do + 90*TimeDelta() to the angle of Seahorse

        // Sub-event, still referring to the first Seahorse
        Conditions: No conditions
        Actions: Move Seahorse to Variable(X) ; Variable(Y)

Thanks for the detailed explanation. :mrgreen:
I could successfully bypass the issue by using a huge Java Script event but your suggestion looks a lot cleaner.

I managed to rewrite the logic as suggested in your post and now the seahorse moves towards the other seahorse but I have a new problem. When the seahorse reaches its destination, a new seahorse is added to the scene. Usually when adding a new object, I can assign property values to only this new instance by referring to the object but in this case the properties are set to both the baby and its mother.

This is my logic:

- For each object loop to iterate through all seahorses and update their logic.
- - State "mating"
- - - Move seahorse to pos x/y
- - - When pos x/y is inside seahorse
- - - - (1) Add object seahorse
- - - - - Set id, size etc. to seahorse <-- this is applied to both the child and its mother

Normally it would only update the new instance but not the others.
(1) I have also tried saving the mother’s id to a temporary variable and when spawning the child add a condition to not equal the mother’s id but then non of them gets updated.
Can I somehow exclude the mother seahorse?

That’s new, but surely it’s the for-each object loop that “mess up” the picked objects list.
No idea if there’s a clean solution, try to add the action “Pick all Seahorse” just before creating the new Seahorse, maybe that resets the pick. If it doesn’t work you could do the loop as now and create the new seahorses without initializing the values, and then in another loop check which seahorses has not some value initialized (for example the ID) and initialize the values.

Btw Javascript is a clean solution for me :smiley: