#Get signal from a script by name?

4 messages · Page 1 of 1 (latest)

finite bay
#

I have a script with an arbitrary number of signals. Then I have a small script that I would prepare for "conneting itself to the signal I specify in the editor" (doing it by hand is not possible, since they are separate scenes that will instance at different times). Given the non-typed nature of GDScript, I would imagine there is a method like get_signal_by_name. There is one called has_signal, which is handy, but even if positive, I would have to hardcode the connection. I just want to prevent a giant match case that can grow over time when I add or modify signals over time. Is this even possible?

uneven ravine
#

Objects have a get_signal_list() method, they also have Error connect(signal: StringName, callable: Callable, flags: int = 0) which looks like what you want.

I do want to throw a framing question out there though: Is this really the only way to architect your project? To my ears, it sound very prone to typos and slight misconfigurations causing big headaches down the road.

finite bay
#

Its more of a proof of concept than a secured architecture to see if I can plug small scripts in a very flexible manner to the signals of the character. It is true that doing things by name is very prone to errors, but i think they would be easy to track, and its much more maintainable than the alternative.
That said, i have another obstacle, and its arguments. Since each signal receives different number of arguments, seems very complicated to unbind the correct number when connecting this generic callback.
I think im overengineering my systems, and I do not want to translate code complexity to the editor, so possibly i will reformulate this. But from a technical point of view, im still interested in knowing how you would solve this situation. How would you connect a callable (with zero args) to a signal you still dont know the name nor the arguments?

uneven ravine
#

I think I need to understand a little more about what you're trying to make before I can give you ideas on how I would architect it. Could you describe what you're making?