Functions
Declaring a function works with the fn keyword. Functions are local by default.
fn Greet(name) { Pewpew:Print("Hello" .. name .. "!")}
Greet("John") // -> Hello, John!Typed parameters and return types
Section titled “Typed parameters and return types”You can annotate parameters with types and declare a return type after the parameter list:
fn Add(number a, number b) -> number { return a + b}
fn Greet(text name) { Pewpew:Print("Hello" .. name .. "!")}
Greet("John") // -> Hello, John!let result = Add(10, 20)Pewpew:Print(ToString(result)) // -> 30Public functions
Section titled “Public functions”Use pub to make a function accessible from other files:
pub fn CalculateDamage(fixed base, fixed multiplier) -> fixed { return base * multiplier}Anonymous functions
Section titled “Anonymous functions”Functions can be anonymous, too! Useful for callbacks.
let Greet = fn(name) { Pewpew:Print("Hello" .. name .. "!")}
Greet("John") // -> Hello, John!Function types
Section titled “Function types”When declaring a variable that will hold a function, use the function type syntax:
pub fn(text, bool) callback // function uninitialized, type requiredThe type syntax is fn(params) -> return_type where both parameters and return type are optional.