Welp, i have another question in regards of code use, i've read that signals are basically another way to call a function, as in, setting up a signal is the same as using "function(variable)", if it's the case, what's the difference between those two?, is using signals at the end more performance-friendly?, or what benefits does it have?, 'cause i've mostly been using direct function calls in my code.
Signals vs normal function call
- Edited
Xrayleader what's the difference between those two?
None in technical sense. Signal is just a name for function callback. Signals provide a neat organizational system for those callbacks.
Xrayleader is using signals at the end more performance-friendly?
They perform same as function calls because they are function calls.
Xrayleader or what benefits does it have?
Convenience and they look clear and expressive in code. You can call a lot of functions (connected signal handlers) with one line of code (emitting) . They come in very handy in situations where many things need to be informed about a single event, which happens a lot in games. By providing signal mechanism, the engine spares you of managing all those callable references on your own. And prior to v4 you couldn't even have callables, you'd have to manage method name strings.
- Edited
Xrayleader Signals are functions but the difference is who initiated the call.
Calling a function is like telling someone what to do. “Go and clean up your room!” You initiate the action.
A signal is like getting a notification from someone, but you don’t really know when. Hearing “Honey I’m home!” You can now choose what to do about this new information.
I think the main advantage of signals is that the signal emitter doesn't need to know the location of the signal listener in the scene tree.
DaveTheCoder A custom list of callables needn't know it either.
What advantage would that have over signals?
- Edited
DaveTheCoder None, it's worse as I already stated above, but either approach doesn't need to know locations of listeners (in the tree) so signals are not advantageous in that respect. In fact the core signal system has nothing to do with nodes. It's implemented in Object
.