Hello there again!
I’m trying to reduce the number of events in my game…
How do you read an object variable in the event?
I have 39 doors in my character selection screen and they all have a different object variable (1 to 39) . How can i make gdevelop know that the player clik on the door number 5 and not the number 20 ( for exemple).
For now i have 1 event for each door and i would like to make 1 event for all of them…
Hope you understand what i mean
You have to use the expressions:
to read numbers and:
to read string values.
No idea how you’ve called your object variables, but imagine you’ve set a different variable “destiny” to each door object, the door with variable “destiny” = 5 means that clicking on it will move you to the fifth level. And you conveniently called the scenes like this: “Level1”, “Level2”, etc., so the fifth level is called “Level5”.
So far so good, with this perfectly made structure you can do it:
Conditions: Left mouse button pressed
Cursor is over Door
Actions: Change to scene "Level" + ToString(Door.Variable(destiny))
If you click on the fifth door, Door.Variable(destiny) is = 5, then ToString(Door.Variable(destiny)) = “5” and finally you can concatenate strings, so “Level” + “5” is = “Level5”
You can make it even easier if you set the variable “destiny” as a string variable with the name of the scene the door has to go, for example to the fifth door the variable “destiny” would be = “Level5”, then in events the action would turn into:
Change to scene Door.VariableString(destiny)
All this assuming you want to change scenes… because you’re talking about doors. But you get the idea, it will work anywhere
Success with your help thanks!