VButtonContainer and functions

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

How can I connect Button in VButtonContainer to functions? If i use get_node("VButtonContainer/0").connect("pressed",self,"_myfunction") I get “Attempt to call function ‘connect’ in base ‘null instance’ on a null instance.”

:bust_in_silhouette: Reply From: volzhs
func _ready():
	get_node("VButtonArray").connect("button_selected", self, "on_button_selected")

func on_button_selected(button_index):
	print("button pressed ", button_index)

Thanks, but this way all buttons are connected to the same function, if I have 4 buttons how can I connect each of them to a different function (button1->function1, button2->function2 …)?

Tetragono | 2017-01-31 16:17

what about this?

func on_button_selected(button_index):
    if button_index == 0:
        function1()
    elif button_index == 1:
        function2()

volzhs | 2017-01-31 16:20

Exactly what I was trying to do, thank you!

Tetragono | 2017-01-31 16:31