Topic was automatically imported from the old Question2Answer platform.
Asked By
rogerdv
In my game, the player must answer a question whenever he/she hits a door or is catched by the enemy. I know how to instantiate the scene containing the question UI, but I cant find a way to tell that scene that it was invoked to open a door or because of the enemy catching the player (each case uses different sources to get the questions). How can I set a parameter or send some value to the scene to indicate the mode it should work?
If you have the instance, you can call any of it’s function and set/get all of it’s variables. So if your question-UI-scene has a var invoked_by, you could do:
var new_question = load("<PathToQuestionUiScene").instance()
new_question.invoked_by = "door"
add_child(new_question)
Setting the variable first and then adding the instance to the tree ensure, invoked_by is already set when _ready() is called.
So, the script should be in the top node of the scene, isnt it?
rogerdv | 2020-02-27 18:00
Yes, for my example above I assumed this. However, you also could do:
That’s of course assuming your QuestionUiScene has a child-node called “Child”, which itself has a child-node called “ChildOfChild”, which has a script attached, that defines the variable invoked_by. But I think you get the idea.