Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Get input from an instanced scene
- 0 votes
- Hello!
- I created a scene to use it as a custom Popup dialog.
- Its structure is:
- -Panel
- --TextureFrame
- --Label1
- --Label2
- --Button1
- --Button2
- I would like to know (from the root scene that will load this custom scene) when and which of the buttons was clicked. How do I approach this, please?
- Greetings
- gdscript scenes instance nodes button
- asked 3 hours ago in Engine by Not_a_Robot (47 points)
- 1 Answer
- +1 vote
- Best answer
- When you have to communicate with the parent scene, a nice approach is to use signals.
- So you can have a script in your Panel that basically exposes signals this way (partial code):
- signal choice1_selected
- signal choice2_selected
- func _on_Button1_pressed():
- emit_signal("choice1_selected")
- close()
- func _on_Button2_pressed():
- emit_signal("choice2_selected")
- close()
- Then in the scene that contains this panel, you can listen to those signals by connecting a function to them.
- You could connect directly to the buttons, but it's as wrong as accessing private members of a class IMO, and it would break if you change or rename the buttons later.
- answered 3 hours ago by Zylann (1,566 points)
- selected 1 hour ago by Not_a_Robot
- Just for possible future searches:
- In the scene that contains the panel:
- get_node("Panel").connect("choice1_selected", self, "method_to_call")
- And yes Zylann, I asked this question because I thought it was a bit awful to connect the buttons directly.
- Thank you very much! :)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement