Creating a Function - LucFr1746/Minecraft-Coding GitHub Wiki

When creating a function, the code is written like a normal event in Skript.
The following code pattern can be used to create a function. Code parts can be changed.

function functionName(parameterName: type = defaultValue) :: returnType:

  • Function names can't contain white spaces or special characters like (, -, ?, . or /. But can contain underscores (_) and non-English letters.
  • Parameters can be replicated using commas or "and".
  • Functions with no parameters are possible.
  • : type specifies the required type of the parameter to be entered.
    • To accept all types object type can be used.
    • The type can be plural (eg. number -> numbers, entity -> entities) to accept multiple values in one parameter.
  • = defaultValue specifies the value that will be used if this parameter is not entered, so it makes the parameter optional. If a required parameter is not entered when calling the function, the script will give an error while loading.
    • This part is optional.
  • :: returnType used if the function will return something. Make sure to replace returnType with an actual return type (eg. number, text, object, item).
    • If a list will be returned, the type can be plural (eg. object -> objects, item -> items).
    • This part is optional.

Input parameters are taken as local variables in the function code. For example, a parameter named player would be {_player}.

To return a value return %objects% effect is used. Also, this effect would stop the code by using the stop effect.

⚠️ **GitHub.com Fallback** ⚠️