[Solved] Creating an object with a variable in the name

Hi there, I am still fairly new to GDevelop and so I don’t know everything, but I want to have a variable object being created.

If I have 2 objects, named ThingOne and ThingTwo, I want only one to spawn depending on the text of a global variable called ThingList. ThingOne will spawn if the text is One, and ThingTwo will spawn if ThingTwo is the text. In reality, I have many more things than just 2 but this is an example. I don’t want to have to make one unique for every object, I want the object that spawns to be the object whose name (or specified section of the name) matches the content of a global variable

Thanks,
Citizen

Ok, if you already have a global variable, what you have to do in the events is: condition “the text of the global variable is equal to” and in action: “create the thingtwo object” depending on the text that the global variable has.
But for that to happen well you will have to create a separate event where you have to change the text of the global variable.

1 Like

To do that, I’d have to make a condition for each of the object that I want to spawn which is what I want to avoid.
The global variable’s text will be dynamic and will change before this, but once the object is spawned nothing will be changing it anymore.

Maybe you can do something like this:


In the Group of Potential Objects, you need to put the group of objects you may create using that action. That means you need to create a new group with every object you can possibly make a member of that group and put that group’s name in that Parameter Field.

The Name of the object to create is, well, just what it says, the name of the object to create. And then there are X and Y positions to create the object and a Layer to create it in.

2 Likes

That seems to be almost exactly what I’m looking for! I’ll try it.

Edit: It worked! Thank you @Mixen! :grin: