Is there any way to open a popup with a button?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By

I think the title is pretty self explanatory, but anyway, i am trying to script a button node called “Quit” which opens a popup that is like a double-check options but I do not know how I would script the button to do this.

:bust_in_silhouette: Reply From: jgodfrey

As an example, create a simple scene with the following 3-node structure:

Node2D (or whatever you want as a root node)
  +- ConfirmationDialog
  +- Button

Add a script to the root node

Wire the button’s pressed() signal to the script, containing the following code:

func _on_Button_pressed():
	$ConfirmationDialog.visible = true

That’s basically it. When the button is pressed, it’s pressed() fires, which calls the _on_Button_pressed() function in the script. That function simply sets the visibility of the dialog to true, which causes it to become visible.

Just season to taste…