Selecting an Object based on the Value of a Scene Variable?

Hi folks,

I’m having a great time working with GDevelop.

I’d like to do something that seems simple but I haven’t been able to get to work:

Have an event where the Object (for either the condition or the action) is the value of a Variable.

For example,

Do = “hat” to variable MoveThisObject
Do +1 to the position of Variable(MoveThisObject)

I would like this to move the Object “hat”. Then I could have a different event sometimes change the the value of Variable MoveThisObject to “cat”, and then that Object would start moving.

This has come up for me because I am creating a Pokemon-like game where characters act in turn, and I’d like to be able to say that for the purpose of this attack, it’s the Player who takes damage equal to the Enemy’s Strength, but for the purpose of the next attack, it’s the Enemy who takes damage equal to the Player’s Strength. (Etc for whichever attack was chosen).

Thanks for your help.

Sadly it isn’t possible :frowning:
To workaround it I was making an extension that wraps an instance into another object dynamically, but I have problems with behavior related events :neutral_face:

Okay, thanks for the quick reply!

Another way I was thinking that it could be done is if membership of Groups could be changed by events (that way, I could add Player to the Attacker group and Enemy to the Defender group, then swap when it’s Enemy’s action), but I couldn’t find an action that does that.

Is that a thing that’s possible?

No, can not move objects between groups either.

One way to do it is use an object variable to select object. Each object could have an object variable called “selected” for example and it default value is 0. Each turn, you wipe this variable for each object and set the value to 1 for the next object in the turn. Then start moving any object with “selected = 1”.

An other way to do it is using object linking. You could have a “control” object in your scene. It nothing but an invisible object or any visible object in your scene, it doesn’t matter and you could “link” an object to this object using the object linking events to being controlled. Each turn, drop all the links between the “control” object and others and then make a link between the next object in the turn and the control object and start moving any object linked to the controlled object.

When move the object, each object can be the member of the same group and move the group instead, so whatever object in the group has the value 1 or linked to the control object will move and you need to set this up only once for the group and not for all objects individually.

To select next object in the turn, what I would personally do is simply have a scene variable called “current”. I would increase the value of this variable by 1 each turn, and use this variable to pick an object. Each object would have an object variable called ID with an unique value. And say, if the value of current and object.ID is the same, than select that object.
Obviously if the value of current is higher than the number of objects in the scene, reset the value to start from the first object again.

Not sure if I can explain it any better or the solution I offer fit your game , hope it helps anyway.