Get button node in click event

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By agus
:warning: Old Version Published before Godot 3 was released.

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!

:bust_in_silhouette: Reply From: volzhs
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")

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

agus | 2016-05-17 02:14