I don’t believe variadic functions are supported. I’ve seen a discussion or two about adding them to G4 in the github, but I don’t think any of them actually made it in.
As a work around, this could be done with something like a Array. Just a shot using your example:
func my_print(args=[]):
if some_condition:
print("xxx: %s" % [args])
my_print([2, 3]) // "xxx: [2, 3]"
var a = "a"
var b = 2
my_print([a, b, "cde"]) // "xxx: ["a", 2, "cde"]"
Could have conditions in the method that check the size of the args array. Additionally this could also be done with a dictionary instead of an array.
Sorry to hear that godot dose not support.
But, args array is the best alternative way I heard.
Thanks anyway.
As BoxyLlama states, I don’t think you can achieve exactly what you want to do in Godot. However, you can achieve something similar using the callv function. It takes the function name as the first argument and an array of parameters as the second parameter, so the caller doesn’t need to know how many paramters are required, it just needs an array with all the arguments. The function being called must know how many arguments it expects. For example: