0 votes

Hi! I'm trying to make an exit button in godot, as the title says. I tried to put get_tree().quit() in a script but not worked. Any solutions please? I'll post the button's script and the tittlescreen script.

Button.gd:

extends Button

func _ready():
    pass

func _on_Button_pressed():
    get_tree().quit()

TittleScreen.gd:

extends Control

var scene_path_to_load

func _ready():
    $Menu/CenterRow/Buttons/NewGameButton.grab_focus()
    for button in $Menu/CenterRow/Buttons.get_children():
        button.connect("pressed", self, "_on_Button_pressed", [button.scene_to_load])


func _on_Button_pressed(scene_to_load):
    $FadeIn.show()
    $FadeIn.fade_in()
    scene_path_to_load = scene_to_load


func _on_FadeIn_fade_finished():
    $FadeIn.hide()
    get_tree().change_scene(scene_path_to_load)


func _on_OptionsButton_pressed():
    pass # Replace with function body.
in Engine by (15 points)

Did you connect the signal? Alternatively, you can override _press without connecting it:

func _pressed():
    get_tree().quit()

I've connected the signal, but didn't work. However, I found the answer. I just changed the script to

extends Button

func _physics_process(delta: float) -> void:
    if is_pressed():
        get_tree().quit()

and now it works!

Please log in or register to answer this question.

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.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.