#How do I dynamically connect buttons to dynamically created signals?

5 messages · Page 1 of 1 (latest)

tidal silo
#

new_skill_tab.connect("pressed", _on_skill_tab_pressed)
yep, you can't connect signal to the same pair(object, method) twice. Doesn't make any sense anyway (what do you think should happen)
new_skill_tab.connect("pressed", _on_skill_tab_pressed(skills.skill_name))
This just calls the function _on_skill_tab_pressed. Really, should be obvious it won't work.

What you want is to use Callable.bind:
new_skill_tab.connect("pressed", _on_skill_tab_pressed.bind(skills.skill_name))

This will create a new Callable which binds (remembers) the skill_name and passes it to the on_skill_tab_pressed method when called. If you ever want to disconnect the signal though, you should save this new callable somewhere, because you will need it for disconnect method.

tidal silo
#

it seems you are making this connection somewhere else, it makes no sense to me why you should get that 'already connected' error message if you are using bind( it creates a new Callable which cant overlap with anything else)

#

It seems problem is with using duplicate. I never used it in this context, i just instantiate a scene that I want.
duplicate seems to copy signals among other things by default: https://docs.godotengine.org/en/stable/classes/class_node.html#enum-node-duplicateflags

#

yep duplicate for Nodes is one of the functions that is hilariously badly documented. Ive never wanted to use it