Callback functions possible in gdscript ?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By trafel
:warning: Old Version Published before Godot 3 was released.

I was just wondering if this was possible :

func c_function(value, callback):
    #Do stuff ...
    callback(value)
    #Do stuff ...

Or just a basic function passing as an argument.

Contrary to Python, functions are not first-class objects in GDScript.
This means they cannot be stored in variables, passed as an argument
to another function or be returned from other functions. This is for
performance reasons.

To reference a function by name at run-time, (e.g. to store it in a
variable, or pass it to another function as an argument) one must use
the call or funcref helpers

GDScript reference — Godot Engine (stable) documentation in English

snesgx | 2020-11-20 16:27

:bust_in_silhouette: Reply From: Warlaan

That’s what signals are for.
If you need more flexibility you can also invoke methods by name or store them in a variable. See here: GDScript reference — Godot Engine (latest) documentation in English

:bust_in_silhouette: Reply From: loganer

what you could do is define the callback function and than pass in self as the parameter.

func callback(something):
    print(something)

func _ready():
    $Anode.Function(self)
func Function(ref):
    #Do something
    ref.callback("OK")
    #Do something