Skip to content

Variables and scopes

A prefix says where a variable lives.

Prefix Where it lives How long Client access
temp. the current function call until the function returns yes
this. the current object while the object exists yes
thiso. the object that started the code, when it runs inside another object yes
player. the player in scope yes
client. account flags of the player in scope forever read and write on both sides
clientr. account flags of the player in scope forever the server writes, the client reads
server. server flags forever server only
serverr. server flags forever the server writes, the client reads
serveroptions. the Server Options forever the server reads; on the client it is always empty
level. the level of the current object yes

Names are case-sensitive: temp.Foo and temp.foo are different. Flag names are stored byte for byte.

function onCreated() {
temp.Foo = 1;
temp.foo = 2;
this.count = 10;
echo(temp.Foo @ " " @ temp.foo @ " " @ this.count);
// expect: 1 2 10
}

Run this example in the playground

A name n with no prefix, not followed by (, is looked up in this order:

  1. A built-in field of the current object (x, chat, dir inside an NPC).
  2. A temp.n variable of this call. Parameters are temp. variables, which is why for (temp.i = 0; i < 3; i++) works.
  3. A const or enum name of this file.
  4. A built-in global such as pi, servername, or screenwidth.
  5. A named global object n that is not a TStaticVar, such as an NPC or a window. Writing n = 5; does not hide it.
  6. A script-global variable n, if it holds a value.
  7. A TStaticVar named n. A named TStaticVar acts like a variable, so after n = 9; the name reads 9.
  8. Otherwise the script-global variable n: empty when read, created when written.

A script-global variable is shared by every function and event of the object and keeps its value between events. It is separate from this.: after zq = 3;, both this.zq and temp.zq are empty. Unprefixed names are an easy way to leak state by accident, so prefer temp. and this. in your own code.

function onCreated() {
zq = 3;
echo(zq @ "|" @ this.zq @ "|" @ temp.zq);
// expect: 3||
}

Run this example in the playground

Inside with (obj) { ... }, this is obj and thiso is the object that runs the code. Unprefixed names reach the built-in fields of obj, not its dynamic variables. Write this.val for those.

Inside new T(...) { ... }, this is the new object. Unprefixed assignments set its built-in fields (such as text of a GUI control); any other unprefixed name is an ordinary variable (a temp. variable if one exists, otherwise a script-global). Write this.name to set a variable of the new object (OQ-LANG-16).

On the server, player is the player that caused the event: the one who sent a trigger, entered the level, or touched the object. With no such player it is empty. On the client, player is the local player.

prefix.(@expression) reads or writes the variable whose name is the text of the expression. The parentheses and the @ are required. The name may hold any bytes, including spaces.

function onCreated() {
for (temp.i = 0; temp.i < 3; temp.i++) {
this.(@"slot_" @ temp.i) = temp.i * 10;
}
echo(this.slot_2);
// expect: 20
this.(@"Pyro Mage") = 3;
echo(this.(@"Pyro Mage"));
// expect: 3
}

Run this example in the playground

A dotted name inside @(...) is one name, not a path (OQ-LANG-17). getstringkeys("this.slot_") lists the variables whose names start with a text.

makevar("temp.name") resolves a full name, prefix included, at run time. It can stand on either side of an assignment. After temp., this., thiso., or level., more dots walk into objects: makevar("temp.obj.hp") is the variable hp of the object in temp.obj (OQ-LANG-17).

function onCreated() {
makevar("temp.mv_" @ "x") = 5;
echo(temp.mv_x);
// expect: 5
}

Run this example in the playground

this.name and this.id cannot be changed. Writing them in plain code is a compile error (E-READONLY-FIELD). A write through a dynamic name is a run-time error and changes nothing.

Names such as level, head, and dir are built-in fields. They hide your own fields and parameters with the same name. The compiler warns (W-RESERVED-NAME). Pick other names.

Engine version 0.1.0. Built 2026-11-18.