Call Objects From Other Events [SOLVED]

Well… I would like know how to call an object from other event (the post’s title :slight_smile: )

I’ll explain this: When you use a condition with an object, for example “Object” is in collision with “Object_2”. in the actions of this event, when you use the object “Object” or “Object_2” (and if you didn’t use the action “consider all objects”) GD will automaticaly consider only the colliding objects (I think in Self Functions of C++).
But if in other event after that, with other conditions, or conditions with other object “Object” and “Object_2”, I make some actions, how can I use the other obects, the objects in collision in the first event?
The only way is with object’s variables?

Tell me if you didn’t understand, and I’ll take some image.

No replies… OK, anyway here are some images, if you didn’t understand:

I have this nice scene:

Then I make this events:

And it will happen:

Finally, If I make this events (look what ball I want move):

It will happen:

But I want It happen:

Really I need some help with this, for example if I use a ball in a condition but I want use the values or object variables from other ball in the actions :frowning: , if I could make an Object into a variable, or if the objects would has a personal ID… :laughing:

2.1 brings option of changing variables of instance of object in scene editor, so what you can do is to add variable called ID and make it different value for every object instance. Then you loop through every object of specific type checking if it has “right” ID value and if so, doing your action. Unless you make objects dynamically, of course (if you do, I’ll try to do some example how to resolve it.)

Yes, it is usefull, but in the actions I need some option to select other object depending this ID Variable, or something like this: if I know the ID of the ball that is in collision (ID = 0) and the ball that isn’t in collision (ID = 1), when I do:

Conditions: Ball isn't in collision with Ground (Ball with ID = 1)

I can’t move the Ball with ID = 0, only I can do:

Actions: Move Ball to 50;50

I try to make a Sub-event:
Event: Conditions: Ball isn't in collision with Ground (Ball with ID = 1) Actions: ---
Sub-event: Object Variable (ID) of Ball = 0 (to refer the other Ball) Actions: Move Ball to 50;50

But didn’t work, because in the Sub-event you can’t refer to other object, you are adding a Condition to the same object, so the Ball will move if is in collision with Ground and it’s ID Variable is 0, and it is False… doesn’t move any Ball.

No, no, no! You need “For each ball” in subevent, and in this for each ball you need to check for id. Will launch GD and make example.

//edit: And here it is: . Instructions are in scene, and events are pretty understandable, I think.

//edit #2: @4ian: You’re free to put this example in next version of GD, if you want.

I see… sototo gave me another idea: only with a variable. Look this:
The variable “Ball_Collision” = 0, when any ball is in collision with the ground do the variable “Ball_Collision” = 1.
Then, in other event, with the conditions that variable “Ball_Collision” = 1 and a ball isn’t in collsiion with the ground move the ball.

Also work, because the condition of the ball in not-collision with the ground is in a different event… some extra job… but works!

We have two solutions, from sototo and Darkhog, SOLVE

Still, I think my solution is more flexible since if you have more balls, you can assign them different IDs. Sototo’s solution is valid, but only if there are only two balls/other objects. With any more it’ll fail.