Function
Defining Functions¶
A script can be declared as a function by including the FUNCTION
header at the top of it. Function names can be given special characters using the same syntax as Variables.
Parameters¶
Parameters can be added to the function using the PARAM
header. The order the headers are listed will be the order the arguments appear in when calling. Parameter names can be given special characters using the same sytax as Variables.
Parameters can be made optional, plural, or both by putting the optional
and plural
keywords before the type.
FUNCTION killPlayer;
PARAM killCauses: plural str;
PARAM assisterUUID: optional str;
PARAM itemsToDrop: optional plural item;
Optional parameters can specify a default value by placing an equal sign and the value after the type.
To access the values passed into a parameter, use a line variable of the same name.
Limiations
Due to the quirks of DiamondFire, parameters have a few limitations that are uncommon to encounter but still important to know:
- Functions cannot have more than 26 parameters.
- Parameters that are both optional and plural cannot specify default values.
- Parameters typed as lists or dictionaries cannot specify default values.
- Parameters typed as variables cannot have the optional or plural modifiers applied.
Return Value¶
Functions can specify a return type using the RETURNS
header. This also allows the function to be used in expressions.
If a RETURNS
header is present, a value can be placed after the return
keyword to return it.
Calling Functions¶
Functions can be called using the call
keyword followed by the function's name.
Arguments can be provided inside parentheses following the function name.
If a function returns a value, it can be used in expressions.