Provide dedicated virtual "signal-response" methods on objects #4793
mieldepoche
started this conversation in
Scripting
Replies: 1 comment
-
I agree that it's annoying to write the connections but this is a bit too automagic I think, I'd still like signal connections to be clearly defined. But there could be much better syntax sugar, like using annotations to connect functions: @connect(body_entered)
func _on_body_entered(body):
pass This would essentially add the appropriate connect code to "_ready". This should work for all the features of signal-connections. You could refer to a signal elsewhere in the tree and bind more variables etc. If you want to support ultimate laziness then an "empty" connect-annotation could infer the signal from the function-name by stripping the "_on_"-prefix. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Quite often I need to connect signals on an object's own script:
Taking inspiration from the dedicated notification response (
_process
,_physics_process
...), what about providing virtual methods that if defined are automatically connected to their signal?{signal}
, add a method named_on_{signal}
_init
, connect signals to overriden methods (with default connection flags):_on_{user signal}
could be detected and connected too maybe, but providing autocompletion for inexistent methods is another problemBenefits:
_process
et al.: provide a simpler-than-the-generic-case interface which enables itself upon usageLimitations:
While I felt the need for such a feature several times, I can't decide if it makes actual sense.
What do you think?
Beta Was this translation helpful? Give feedback.
All reactions