Problem with attach a function to button created at runtime

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Tomi

Hello everybody!

I used the code from here to create a button at runtime and attach a function to it:

func _ready():
var button =
button.text = "Click me"

func _button_pressed():

But when I run my program, it gives me the following error message:
Invalid get index ‘_button_pressed’ (on base: ‘Node2D (’). Did you mean ‘._button_pressed()’ or funcref(obj, “_button_pressed”) ?

If I try so: button.pressed.connect(self._button_pressed**()**)
I also get an error message: Invalid call. Nonexistent function ‘connect’ in base ‘bool’.
What is wrong with this? Maybe button creating is not working in Godot 3.3 in this mode, only in Godot 4.0?

:bust_in_silhouette: Reply From: godot_dev_

Try changing button.pressed.connect(self.buttonpressed) to button.connect("pressed",self,"buttonpressed")

The syntax for connecting to signals is different from Godot 4 and Godot 3 I beleive

:bust_in_silhouette: Reply From: HyperlinkYourHeart

You’re looking at the Godot 4.0 documentation. The way that signals are hooked up changed in Godot 4. Take a look at the docs for Godot 3.3.