Skip to content

Functions

expOrbit supports defining functions. Unlike variables, functions are global. You can access them "out of order" in files.

Defining

Functions are defined using the def keyword. They can be given any amount of parameters. Its important to note expOrbits does not currently support optional arguments.

1
2
3
4
5
6
def foo(a, b) {
    return a + b
}

x = foo(1, 1)
z = foo(2, 2)

Returning

Functions must return a value. This is done with the return keyword.

1
2
3
4
5
6
7
8
9
--[[ this function will return 1 if called ]]
def foo() {
    return 1
}

--[[ this function will error if called ]]
def foo() {
    x = 2
}

Functions can also have nested returns. When nesting and using conditionals, ensure your function always returns a value!

1
2
3
4
5
6
7
8
9
def foo(a) {
    if (a > 10) {
        return a / 10
    } else if (a < 5) {
        return a * 2
    }

    return a
}

Global Functions

Functions are always global. This means you can call them out of order in expOrbit files.

1
2
3
4
5
6
7
def foo(a, b) {
    return add(a, b)
}

def add(a, b) {
    return a + b
}

Warning

Variables are not global. The following example will error!

1
2
3
4
num = x + z --[[ x and z have not yet been defined! ]]

x = math.sin(t)
z = math.cos(t)