Functions

  • You can define a function on 2 ways. Being named or being anonymous. both of them can be localized by putting “local” infront of them.
  • Named
function example() {
        return 42
}
  • Anonymous
example = function() {
        return 42
}
  • Arguments can be supplied too ofcourse
function argfunc(argA, argB) {

}
  • you can also make your function typesafe by putting a type infront of it now you’re sure that everything that gets trough will be a number
function typesafefunc(number a, number b) {
        return a * b
}
  • Strings, bools and numbers get copied as arguments, rather than references, as that’s what you’d expect all others will be sent as references if you don’t want to copy them, that’s okay. you can tell the compiler to stop it’s evil cloning process and pass it along as reference anyway by using the & sign infront of the name
function test(number &a, number b) {
        a++
        b++
}

local numa = 0
local numb = 0
test(numa, numb)
print(numa, numb)
  • Output will be 1<tab>0