How I can create a callback mechanism or signal in class. Let's say I have created a class and I want to be able to execute a callback when some internal events happen.
I am wondering if something like that would be implemented for class. I suppose not as it is not a Node but only class:
class SimpleExample:
signal my_signal
func some_func():
emit_signal(my_signal)
The callback that I wrote is also not ideal solution. For example:
class SimpleExample2:
var my_callbacks = []
func add_callback(fun_name):
// check if not already added
my_callbacks.append(fun_name)
func some_func():
// some interal calculations
for fun in my_callbacks:
call(fun)
But that will not work because my_callbacks are just strings so the call function do not know which node/object is the owner. It will simply try to run that name (fun) as the function.