Variables and scopes
Prefixes
Section titled “Prefixes”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
Names without a prefix
Section titled “Names without a prefix”A name n with no prefix, not followed by (, is looked up in this order:
- A built-in field of the current object (
x,chat,dirinside an NPC). - A
temp.nvariable of this call. Parameters aretemp.variables, which is whyfor (temp.i = 0; i < 3; i++)works. - A
constorenumname of this file. - A built-in global such as
pi,servername, orscreenwidth. - A named global object
nthat is not aTStaticVar, such as an NPC or a window. Writingn = 5;does not hide it. - A script-global variable
n, if it holds a value. - A
TStaticVarnamedn. A namedTStaticVaracts like a variable, so aftern = 9;the name reads9. - 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
with and initializer blocks
Section titled “with and initializer blocks”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).
player
Section titled “player”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.
Dynamic names
Section titled “Dynamic names”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
Read-only fields
Section titled “Read-only fields”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.
Reserved names
Section titled “Reserved names”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.