Functions
Declaring
Section titled “Declaring”function name(a, b) { return a + b;}A function can be marked public or private, and async when it uses await. Function and event names are not case-sensitive. Two functions in one file whose names differ only by case are a compile error (E-DUPLICATE-FUNCTION).
Parameters are temp. variables of the call. You may also write temp.a in the parameter list.
Two forms that the legacy server compiles are accepted so old scripts load unchanged. A return type after the parameters, function f() : void, is ignored. A parameter written with a dot that is not temp., such as function f(player.account), binds nothing: the argument is dropped and the name reads empty. Two functions with the same handler object, function Obj.onEvent() twice, are allowed and the later one replaces the earlier one; a repeated plain function is still an error.
A parameter may carry a type and a function a return type, as in function easeOut(t:Number, b:Number):Number. The types are accepted and ignored, so scripts written for the legacy server compile as they are. (For types that the editor does check, see type annotations.)
Arguments
Section titled “Arguments”- A missing argument is
0. An empty value passed as an argument also arrives as0. return;, or reaching the end of the function, gives0to a script caller.- An extra argument is ignored by the parameter list.
paramsis an array of all arguments, but only when the function runs as an event (started by the engine, bytrigger, byscheduleevent, or by a trigger from the other side). In an ordinary call,paramsis empty.
function add(a, b) { return a + b;}
function onCreated() { echo(add(2, 3)); // expect: 5 echo(add(2)); // expect: 2 echo(add(2, 3, 4)); // expect: 5}Run this example in the playground
Return
Section titled “Return”return value; gives a value. return; and reaching the end of the function give empty.
Finding the function to call
Section titled “Finding the function to call”A call name(args) with no receiver looks for:
- A function on the current object: its own code first, then the classes it joined.
- A function value stored in the script-global variable
name(OQ-LANG-23). - A built-in function.
- Nothing: the engine reports
R-UNKNOWN-FUNCTIONand the call gives empty. The compiler warns before that (W-UNKNOWN-FUNCTION) when the name is neither declared in the file, nor built in, nor provided by a class that is joined in the file.
Your own function hides a built-in with the same name. The compiler warns (W-SHADOWS-BUILTIN).
Functions that a class adds with join(...) at run time are not visible to the compiler. Call them through this, as in this.rankFor(points), to avoid the warning, and see reuse.
Who may call what
Section titled “Who may call what”- Inside one object (its own code and its joined classes), every function can be called.
- From another object (
obj.fn(),findnpc("X").fn(),(@"X").fn()), onlypublicfunctions run. Calling a non-public function from outside gives0and reports nothing. privatebehaves like a plainfunction. Use it for readability.obj.trigger("Name", ...)reachesonNamewhatever its visibility.
Calling a function on another object
Section titled “Calling a function on another object”obj.fn(args) runs fn with this set to obj and thiso set to the caller. When obj is empty or destroyed, the call gives empty and the engine reports R-CALL-ON-NULL.
Anonymous functions
Section titled “Anonymous functions”function(params) { ... } is an expression that makes a function value.
- There are no closures. The body cannot read the
temp.variables of the function that created it. thisinside the body is the object that runs it.- A named function is not a value:
temp.k = myFunc;stores0. Pass names as strings.
function onCreated() { temp.outer = 5; temp.f = function(x) { return x + temp.outer; }; echo(temp.f(1)); // expect: 1 temp.g = function(x) { return x * 2; }; echo(temp.g(21)); // expect: 42}Run this example in the playground
Where a built-in takes a callback, it accepts either a function value or the name of a function as a string.
Control handlers
Section titled “Control handlers”function Name.onEvent(...) declares the handler for the event onEvent of the named object Name, usually a window or a control. Both parts ignore case.
Statements outside functions
Section titled “Statements outside functions”Statements outside any function run once each time the file is attached to an object: when an NPC is created or reloaded, or each time a class is joined, before onCreated (OQ-LANG-9). A class file often starts with join("other_class");.
Engine version 0.1.0. Built 2026-11-18.