GML when I choose another instance this one takes the value of the previous one


(sorry for my bad English, I'm Belgian)
I select an instance, it follows a path, at the end of it I modify a variable of this instance.
The problem is that if I select another instance of the object while the first continues its path, when the path is finished, the variable of the second instance is changed.
I'm looking for 6 weeks!
If I select another instance of the object, it should be the object selected from the beginning that changes when the path is completed.
thank you in advance for your help.

This is the code of creation:
global.arrCar = array_create(5);
global.arrCar[0] = instance_create_depth(639,286,1,objCar);
global.arrCar[1] = instance_create_depth(639,159,1,objCar);
global.arrCar[2] = instance_create_depth(703,159,1,objCar);
global.arrCar[3] = instance_create_depth(767,159,1,objCar);
global.arrCar[4] = instance_create_depth(831,159,1,objCar);
global.arrCar[5] = instance_create_depth(831,286,1,objCar);

when I select a objCar:
global.idCar = instance_nearest(x,y,objCar);

Global variables are available to all objects / instances.

If you want a path ending to change an instances variable, then you can do that within the instance itself - and only affect itself.

Under "add event" there is "other": within this is "end of path". A function that only happens when a path is assigned, and has been finished.

If the variable you want to change is always the same, and any time they have a path it will always do this, you can set the variable within this event. Put this in the object that will be following the path.

You may have some other problems due to using global variables, but without seeing all of your code it's hard to say. This suggestion should fix your path issue.


Hello, I'm back because doesn't works. I developed my question/issue with pictures below.


I have 2 objects, 2 paths and a button.

I select the instance of the object (green round) and I push the button to launch the command 'path_start'.

At the end of this path, the object variable take a value like 'move = 0'.

The problem: if I select the other instance (picture 2) before that the first one is at the end of her path, the second instance take the value 'move = 0' instead of the first.

picture 2

when I click on the object instance: global.idCar = instance_nearest(x,y,objCar);

Button code:

I have of course an event 'Path Ended':



I'm completely lost!

Thanks in advance for your help.

You are not setting the path in the object that travels it.

If the path is not generated in that object it will need to be given a duplicate for itself.

Then it can have it's own path end event, setting it's own variable 'move'.
path end event (of whatever instance):
move = 0;

If 'move' is meant to be a global variable:
path end event (of whatever instance):
if move == 0
can set move
other instance has already set 'move' value, and so reached end of path first