Functions#
Functions are reusable procedures (custom blocks) that can return values, including primitives or structs. Functions always run in Run without screen refresh mode and must only be called from other Run without screen refresh procedures or functions to prevent undefined behavior.
Each function must end with a return
statement. Using stop_this_script
inside
a function is undefined behavior.
Declaring a Function#
Use the func
keyword to define a function. Optionally, include a return type for
functions that return a struct.
Default Argument Values#
Function parameters can have default values, allowing callers to omit them:
greet()
returns"Hello, world!"
greet("aspizu")
returns"Hello, aspizu!"
Calling a Function#
Functions are called by name with argument values:
Keyword Arguments#
You can also call functions using keyword arguments, which specify parameter names explicitly. This is useful when using default arguments or calling functions with many parameters:
This behaves the same as greet("aspizu")
, but makes the call more readable—especially
when multiple parameters are involved:
func introduce(name, title = "developer", location = "unknown") {
return $name & " is a " & $title & " from " & $location;
}
Call it with keyword arguments: