Godot 4.5 - varargs
Godot 4.5 added support for functions with variable number of arguments. Also known as variadic functions. They look like this:
func warning(...msg: Array) -> void:
var message: String = " ".join(msg.map(str))
print("WARNING |", message)
- You can put some other arguments before the variadic one. Similar to Python’s
*args, **kwargs
- those have to be at the end too - The type of the variadic argument has to be an untyped
Array
People have been asking for them for literal years, so even now when I google Godot varargs function, the top result says they are not supported. Well - they are now! See more examples here!
I’m writing this article just to help to turn the tide of SEO. Go, Godot!