Godot Version
4
Question
How can one declare that a parameter expects a function? And/or declare the types that that parameter function will take / return?
I’m coming from TypeScript, and that’s a pretty common operation there, with code similar to what’s below. But in GDScript I’ve tried extrafunc: (() -> void) = null, extrafunc: Function, etc in the parameters array and all of it’s giving me compiling error. The page on types doesn’t seem to include functions in the syntax it displays.
Thank you!
const string = "hello world";
const paramfunc = (key: String) => {
return key.length;
}
function my_target_function(str: String, paramfunc: (key: String) => int) {
return paramfunc(str);
}
my_target_function(string, paramfunc)
^ How to do this kind of thing in GDScript…?