Godot Version
Godot 4.2.1
Question
Hello, I want a button to call a function when it’s pressed. Since there will be many buttons, I want to use connect() instead of on_pressed(). Can anyone help me?
I tried this (wa and bo are the buttons):
func _ready():
$SelectMenu/wa.connect("pressed", asign_player("wa", true))
$SelectMenu/bo.connect("pressed", asign_player("bo", true))
func asign_player(who : String, is_on_left : bool):
if is_on_left:
left_player = who
if is_on_left == false:
right_player = who
print("right player: " + right_player + " left player:" + left_player)
It gives me the following error:
Invalid type in function ‘connect’ in base ‘Button’. Cannot convert argument 2 from Nil to Callable.
Thank you.