Skip to main content

Functions

A function is a block of code that you can use multiple times to peform a particular task. The syntax is:

func [function name](<args>) {    [code]}

The function name follows the same rules as a variable name. Next, are the arguments. These are optional, and are seperated with commas. The maximum amount of arguments for a function that you can have is 255. Here is an example of it:

func add(num1, num2) {    return num1 + num2}
print(add(1, 2))print(add(14, 6.54))print(add(123, -11))

This is a basic function that takes 2 inputs, then returns the sum. Returning a value stops the fuction, and returns the value in the statement. This means that proceeding code after the statement will not execute. If there is no expression or no return statement, the function automatically returns null.

You can also set optional arguments by adding a ? after the argument name, like this:

func test(arg1, arg2?) {}

If no arg2 argument is passed, the arg2 will be automatically assigned to null.