Using a text variable to replace an object's name

Hello!
I’m working on a game where I want to give the player the feeling that they can modify the game’s reality by typing key words inside the game.
For example, I would like the player to be able to complete the sentence “Change all X into Y” by typing names for X and Y. So if the player types ‘Spike’ for X and ‘Key’ for Y, all the spikes should be changed to keys.
Now here is my problem: I can’t find a way to use a variable to store an object’s name and then to act as if it was the object’s name itself.
In the screenshot below, the instruction block marked in Red works perfectly fine (if the player types ‘Key’, all the Spikes are replaced by Keys). But in the instruction block marked in Green, the instructions are the same as previously, but the object’s name ‘Spike’ is stored in a scene variable. But this block doesn’t work, and I get an error message saying “Enter the name of an object” when I type the name of my variable containing the name of the object.

I hope I managed to explain my problem clearly enough, and I thank you in advance if you can find a solution to use a variable’s text to act as an object’s name!

Thanks a lot!

  • GingerBread

If that doesn’t work, try to make a group with your objects, and use that group as name. Then add another condition to check if the object name matches the Name variable.

Thank you for your answer!
However, the solution you propose is not very satisfying for my problem. My goal is to avoid testing whether the variable matches one of the objects names one by one. Your solution would work indeed, but would constrain me to copy-paste my block of instructions for every different possible object, which I think is largely under-optimal (I guess?). That’s why I need the content of the variable to be considered directly as an object’s name, that I can use directly in the event’s conditions and effects. Do you see a way to do that?

Thanks again for your assistance! :slight_smile:

  • GingerBread

No copy-pasting needed, that’s the point of switching to group.

Ok!
It took me a bit of the work because I wasn’t sure to understand how to use groups in this situation, but I finally got over it.

Thank you for your help! :slight_smile:

  • GingerBread
1 Like