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:
https://docs.godotengine.org/en/stable/classes/class_button.html

func _ready():
var button = Button.new()
button.text = "Click me"
button.pressed.connect(self._button_pressed)
add_child(button)

func _button_pressed():

But when I run my program, it gives me the following error message:
Invalid get index ‘_button_pressed’ (on base: ‘Node2D (palya1kodja.gd)’). 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.