Open me2beats opened 4 years ago
often when connecting a signal, I cannot know in advance whether the signal has already been connected to a method.
This doesn't sound like common problem and implies that something is wrong with your code. I never had this issue nor seen anyone mentioning it before.
@KoBeWi I often face this problem when creating tool scripts/editor plugins.
Some frameworks do these checks by default (for example kivy bind)
Describe the project you are working on: gdscript editor plugins
Describe the problem or limitation you are having in your project: often when connecting a signal, I cannot know in advance whether the signal has already been connected to a method. In this case, I should use
if not obj.is_connected()
, otherwise I get the errorthis check (using
is_connected
) makes the code noisier and less readable.Describe the feature / enhancement and how it helps to overcome the problem or limitation: I think it would be convenient to check a connection when using
CONNECT_CHECK
flag inObject
connect
method.Describe how your proposal will work, with code, pseudocode, mockups, and/or diagrams: enum ConnectFlags: CONNECT_DEFERRED = 1 CONNECT_PERSIST = 2 CONNECT_ONESHOT = 4 CONNECT_REFERENCE_COUNTED = 8 _CONNECTCHECK = 16 Connect a signal only if it is not connected
the same goes for the
disconnect
method.connect_check
parameter or flag could have been implemented to free a user from having to useis_connected()
If this enhancement will not be used often, can it be worked around with a few lines of script?: It's possible to create a
ConnectUtils
class and a static function something likeconnect_once()
in it (orConnectUtils
singleton withconnect_once()
method) that would do the connection check, but this generates additional dependencies and it is not much more convenient than just usingif ! is_connected()
in the code every time. Using a flag would be more convenient imo Is there a reason why this should be core and not an add-on in the asset library?: Theconnect
method belongs to theObject
class, so I think it would be more logical and handy to have this feature in the core.