This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
+4 votes

How we can get the button reference on the event function that is connected?
Lets say:

var b
func create_button():
    b = Button.new()
    b.connect("toggled", self, "button_toggled")

func button_toggled(toggled):
    # I WISH I WOULD HAVE HERE THE THE BUTTON OBJECT OR AT LEAST THE 
    # NAME ON THE BUTTON.
    if toggled == true:
        print("Button is pressed")
    else
        print("Button is released")

Any way at least to do this? Thank you very much!

in Engine by (45 points)
edited by

1 Answer

+4 votes
Best answer
var b
func createbutton():
    b = Button.new()
    b.set_name("button 1")
    b.connect("toggled", self, "button_toggled", [b])

func button_toggled(toggled, target):
    print("which button = ", target.get_name())
    # I WISH I WOULD HAVE HERE THE THE BUTTON OBJECT OR AT LEAST THE 
    # NAME ON THE BUTTON.
    if toggled == true:
        print("Button is pressed")
    else
        print("Button is released")
by (9,800 points)
selected by

THANK YOU VERY MUCH, IT WORKS LIKE A CHARM! :)

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 Frequently asked questions and 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 [email protected] with your username.