+1 vote

I was just wondering if this was possible :

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

Or just a basic function passing as an argument.

in Engine by (117 points)
edited by

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


1 Answer

+4 votes
Best answer

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: http://docs.godotengine.org/en/latest/reference/gdscript.html#functions

by (1,120 points)
selected by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.