0 votes

I'm pretty new to the GDScript language, but I know that functions in GDScript aren't first class, so you can't store them in variables. I know about FuncRef and how to use them to (somewhat) store functions in variables, but I don't think it works with built-in functions, like floor and round.
I'm (more, at least) familiar with Python, and in Python i can store functions and call them in this way:

functions = [abs,max]
foo = functions[0](-1) # basically abs(-1), which is in turn 1

I'm trying to do this in GDScript, what's the closest GDScript equivalent?
I've tried to RTFM, but I don't think i've seen any mentions of FuncRefs being used with built-in functions in the docs.
There are some workarounds I can do i.e. wrapping the built-in function, but it feels dirty.

Godot version 3.3.4
in Engine by (26 points)

1 Answer

+1 vote

I think there already is implementation of lambda function in godot 4.0 (but not backported)

see below


I think this might be possible with lamda?

by (236 points)
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 Frequently asked questions and 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.