Hello, Let's say I have 2 buttons "Eat" and "Drink". I want to connect them to a popup to confirm "are you sure [yes]/[no]" then if [yes] then it executes eat() or drink() accordingly.
Thank you
Hello, Let's say I have 2 buttons "Eat" and "Drink". I want to connect them to a popup to confirm "are you sure [yes]/[no]" then if [yes] then it executes eat() or drink() accordingly.
Thank you
You could write a custom signal, like open_popup
. When you create the signal, you can pass optional arguments. In your case, you probably want to use a String or Enum. String is probably the easiest, and for two options you don't have to get fancy. Then in the signal callback, you give it a variable in the function. Let's say it's called `kind'. Then you can check it.
if kind == "eat":
eat()
elif kind == "drink:
drink()
cybereality thanks I will give it a try
Sorry I'm still lost. Consider this scenario:
Tree:
Control #script
-Button #signal
-Button2 #signal
-ConfirmationDialog #signal
-Label
Script:
extends Control
func _on_button_pressed():
$ConfirmationDialog.visible = true
func _on_button_2_pressed():
$ConfirmationDialog.visible = true
func _on_confirmation_dialog_confirmed():
$Label.text = "Text here depends on which button pressed"
Both Buttons will activate ConfirmationDialog. It has its own Yes/No buttons. If Yes (confirm) is pressed I would like the Label to show text depends on which button was originally pressed. How to do this?
Both buttons should map to the same signal, but pass a String argument. This is set in the UI or in text (if you do it with code). The if statement I showed would go in _on_button_pressed, which both buttons call.
Look under the advanced options.
Followed your instructions I got both buttons to change the label with this signal:
func _on_button_pressed(a):
if a == "but":
$Label.text = "but"
elif a == "but2":
$Label.text = "but2"
But how do I get the ConfirmationDialog to confirm before it changes the Label text?
Probably the easiest way would be to use a temporary variable that is part of the class. Like:
# top of script
var confirm_text
# button signal
func _on_button_pressed(a):
if a == "but":
confirm_text = "but"
elif a == "but2":
confirm_text = "but2"
# dialog signal
func _on_confirmation_dialog_confirmed():
$Label.text = confirm_text
cybereality Thanks so much!