Add Signal keyword in front of functions designed to be connected by signal with GDScript #7930
NerdChickenGames
started this conversation in
Scripting
Replies: 3 comments
-
WDYM by "function defined for use by signals"? GDScript is a duck typing language - if it quacks, it's a duck. |
Beta Was this translation helpful? Give feedback.
0 replies
-
I would prefer it to be an annotation rather than a |
Beta Was this translation helpful? Give feedback.
0 replies
-
See also: #7112 |
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
-
Signals are one of the best and powerfull feature from Godot to create and connect GUI with game behaviors ! This feature is particularly useful when you're working in a team and the other members have no programming skills.
But in some cases, the ability to add functions on the fly within a script can become problematic.
Description of current situation
It is now possible to connect signals between nodes via the Godot interface with just a few clicks. This is particularly useful for people with no programming skills (gamedesigners, interface designers, etc.).
When creating extended custom nodes with scripts, it is possible to define node-specific signals. And when you want to connect two custom nodes with signals, the godot interface allows you to either create a specific class method such as _on_my_button_pressed() directly in the script, or use an existing method in the script via the "Pick" option in the dialog window.
The main problem with this feature is adding a function directly to the script, or using a function that is not designed for use with signals. As a developer, it would be interesting to block the creation of a function by Godot in the script when connecting a signal.
It would be interesting to force the user to connect the signal to script functions that have been specifically created for this purpose. The aim is to prevent the misuse of certain functions within the team.
Solution proposal
A simple solution would be to add the Signal keyword in front of functions designed for use with signals. Using this keyword would automatically block the addition of new functions by the Editor in the script, and only compatible functions would appear in the signal selection window.
Example
In the script, we add the Signal keyword in front of the function. The script is automatically "locked" and it is no longer possible for the editor to add signal functions to the script on the fly.
The Receiver Method and functions without the Signal keyword are disabled in the selection window for connecting signals.
I think this would be an excellent improvement, especially when you're working with a team and want to limit the risk of creating unwanted functions within scripts or connecting signals to functions that weren't designed for this purpose.
Beta Was this translation helpful? Give feedback.
All reactions