0 votes

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 ;)

asked Mar 17, 2018 in Engine by mr.fies (25 points)

You mean that instead of the game quitting, running get_tree().quit() just closes the popup instead of actually closing the game?

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.

3 Answers

0 votes

can someone help please?

answered Mar 18, 2018 by mr.fies (25 points)
0 votes

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)

answered Jun 23, 2018 by Valkia-INNOS (14 points)
0 votes

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():

func _process(delta):
    if quit:

func _on_Button_button_down():

Then, add a script to AcceptDialog:

extends AcceptDialog
func _ready():

#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.

answered Jun 23, 2018 by picnic (218 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.