Object variable instead of Object

can i use object variable instead of object in Gdevelop 5???
I have 2 instances (of same object) and want to move only the first instance and not the second one created… please anyone help me or an idea would be great… Help i’m stuck at creating my first game…!
Eg: Rts game where only the selected character will move when clicked and not the others of the same object (or model).
below is the screen shot of what i’m trying to do…

my advice is use object variable instead of scene variable for this task. add an object variable to your gunner object first (without value). I will call it “selected” now.
the istances will inherit this variable, and can hold different value in it. now clone the object (pull the istances to the scene).
in the first event in the screenshot exchange “gunneron” screen variable to the object variable wich you created before (“selected” for me).
and exchange the variable in the second event too.

@Gyuszko
Ok great, This helps me alot.Thank you for ur valuable time…
Again to confirm if I select a Gunner and move it in the game only Gunner I selected will move right?
I’ll make it simple what I’m trying to accomplish, game starts
1.only one Gunner on the scene
2.i click it to select.then move with keys.
3.press r will revoke the action or unselect it.(That’s why the Gunner on variable created)
4.I press N creates another Gunner[obj] instance.
Im happy till this , then when I try to move after selection both Gunner moves .
What I want to happen.
5.only the Gunner I select with mouse click and not all the instances created on the runtime…
I hope this makes clear…Please give me some idea.can I do this without code or do I have to write Js??

yes, we can do it without JS. the only difference my previous post is: you sholud give a starting value to the object variable, wich is tell GDevelop, this instance isn’t selected. and make sure, when you unselect a gunner after use with “r”, set back the variable’s value to default.

for example:

when create an instance, add this action:

  • variable “selected” of gunner set to “no”

and when you select the desired gunner:

  • if mouse on the gunner & left mouse is down :arrow_right: variable:“selected” of gunner set to “yes”

unselect:

  • variable “selected” of gunner set to “no”

There is no need to use JS for something so simple. Already @Gyuszko gave you the solution: you need to use object variables to discriminate between instances.

Here is an example of how to implement it:

Select_instance

@Gyuszko , @erdo
Thanks to both of you for guiding me in right direction. I hope this will be helpful to someone who might come across this problem.
Erdo thanks for the zip file! Easy as you said…

2 Likes