You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
However, nowhere in the documentation for custom functions is there any indication of it being possible to declare a custom function to take a varargs parameter. I tried, as a quick test, declaring a function parameter parameterName as string... (and it was not just the last but the only parameter in that function) but running /ct syntax gave me the error ) expected at that line. I also tried declaring parameterName... as string[] and got the same error.
Can custom functions be declared to take varargs parameters? If so, what is the syntax (and can it be added to the documentation)? If not, can this be implemented?
Final note: I felt this belonged in the ZenScript issue tracker because it's a feature inherent to the language, not the minecraft-specific application of it. If I'm wrong about that, I can open a copy of this on the CraftTweaker issue tracker instead.
The text was updated successfully, but these errors were encountered:
ZS supports the idea of varargs.
However, currently only methods that are declared in the Java Code allow for varargs.
Custom functions in ZS are still pretty limited. They do not allow for varargs.
Heck, normal functions don't even allow for overloading or optional parameters.
Since varargs are just syntactic sugar for an array creation, you can create the array explicitly.
Or you could create a zenClass inside ZS code, and have overloads for the most cases, so something like
zenClassMyClass {
zenConstructor(){}
function doSomething() asvoid {doSomething([]);}
function doSomething(arg0 asstring) asvoid {doSomething([arg0]);}
function doSomething(arg0 asstring, arg1 asstring) asvoid {doSomething([arg0, arg1]);}
function doSomething(arg0 asstring, arg1 asstring, arg2 asstring) asvoid {doSomething([arg0, arg1, arg2]);}
function doSomething(arg0 asstring, arg1 asstring, arg2 asstring, arg3 asstring) asvoid {doSomething([arg0, arg1, arg2, arg3]);}
function doSomething(varargs asstring[]) asvoid{
/*Code here*/
}
}
Looking at the CraftTweaker documentation for
IOreDictEntry
, the example for adding items indicates that varargs functions exist, as shown here:However, nowhere in the documentation for custom functions is there any indication of it being possible to declare a custom function to take a varargs parameter. I tried, as a quick test, declaring a function parameter
parameterName as string...
(and it was not just the last but the only parameter in that function) but running/ct syntax
gave me the error) expected
at that line. I also tried declaringparameterName... as string[]
and got the same error.Can custom functions be declared to take varargs parameters? If so, what is the syntax (and can it be added to the documentation)? If not, can this be implemented?
Final note: I felt this belonged in the ZenScript issue tracker because it's a feature inherent to the language, not the minecraft-specific application of it. If I'm wrong about that, I can open a copy of this on the CraftTweaker issue tracker instead.
The text was updated successfully, but these errors were encountered: