Dynamically connecting a signal to a dynamically created node

Godot Version
4

Question

I created a checkbox that adds each line created to it one by one. This allows for unlimited options that are created by the user one by one. I’ve run into a problem where I cannot connect it to a toggle function which would detect when the state of the checkbox(checked or unchecked) and change the value for its “checked” key to true/false. This is because the toggle function requires the toggle signal which I cannot reproduce dynamically. I tried using connect this way: child.connect(“toggled”, self, “_on_check_box_toggled”)

change to:

child.connect("toggled", self, _on_check_box_toggled)

I tried that but it says it wants the second argument to be a callable and the last one must be a “flag” int value

ok i forgot, it’s not godot 3

child.connect("toggled", _on_check_box_toggled)

this should do it

1 Like

THANK YOU!!!
I’ve learned a lot with that answer alone

1 Like

alternatively you can also do like this

child.toggled.connect(_on_check_box_toggled)

or even

child.toggled.connect(func(_is_toggled):_on_check_box_toggled(_is_toggled))
1 Like

These were even better because I could add another argument to it

You can add more parameters with bind, see the example in the reference