Topic was automatically imported from the old Question2Answer platform.
Asked By
mr.fies
Hi there, I made a Popup → Sprite → TextureButton
I call the Popup with mainmenu.show_modal()
Then I try to quit the game with get_tree().quit() after clicking the TextureButton
What happens is, the Popup disappears. How can I close the game later on? The script to show the Popup and the Button is in the root-node.
Thanks in advance
P.S. I like Godot
You mean that instead of the game quitting, running get_tree().quit() just closes the popup instead of actually closing the game?
Pieter-Jan Briers | 2018-03-18 14:40
Yes, the popup is closed instead of the game. Sorry, english is not my mother language
I also tried self.get_tree().quit() and calling get_tree().quit() twice. Both didnt help.
I don’t know if you are asking for an exit game way, but i hope this helps you:
(example: simple exit game button)
Select the element and on scene tab right click the node corresponding to your button and press attach script
Select the element you want to associate with Exit, go at tab Node (at the side of inspector), select pressed
down at the right of screen press button Connect
you will see something like this —
select your button and click Connect.
Now you will be returned into the main page…
Click script sign and edit your script as shown in the image.
Run the scene to test it. (tested with Godot 3.0.X)
Also late to the party but this might help someone else…
Create a project with a Node2D, and two child nodes: an AcceptDialog and a Button. Link the button’s signal to a function in Node 2D like this, to show the dialog when the button is pressed
extends Node2D
var quit = false
func _ready():
pass
func _process(delta):
if quit:
get_tree().quit()
func _on_Button_button_down():
$AcceptDialog.show_modal(true)
Then, add a script to AcceptDialog:
extends AcceptDialog
func _ready():
pass
#func _process(delta):
# # Called every frame. Delta is time since last frame.
# # Update game logic here.
# pass
func _on_AcceptDialog_confirmed():
get_node("..").quit = true
When the used confirms via the dialog’s OK button the ‘quit’ variable in Node2D is set to true and when control returns to Node2D the app is closed in the next call to _process.