Noverwyn Documentation

Scripting

Scripts are written in Luau. They all run on the server.

A script#

A folder in scripts/ with a main.luau file. The folder name is the script name: letters, digits, _ and -.

scripts
├── lib
│   └── noverwyn.luau    ← the library, loaded before each script
├── school
│   └── main.luau
└── vip
    └── main.luau

Its life#

  1. Start: the file is read from top to bottom, once.
  2. Running: it receives events, zone entries and exits, timers.
  3. Stop: it receives stop, then the server itself removes its zones, its entities and the buckets it bound to zones.

The console commands start <name>, stop <name> and restart <name> work while players are connected.

What it has#

The functions of the native reference, and the Luau standard library: math, string, table, coroutine, bit32, buffer, utf8, os (date and time), vector.

No files, no network, no require. Shared functions are protected: a script cannot modify them.

Each script is alone#

Each script has its own environment. A global variable is not seen by the others. To communicate, use entity properties, with the server scope if needed:

-- script A
player:set("points", 10, "server")

-- script B
log(player:get("points"))

Its limits#

Limit Default value
memory 32 MB
time per tick 50 ms, all calls included
time at startup 1 second
overruns on the third, the script is stopped; one overrun is forgotten every 200 ticks

An error in a function is written to the console with its trace. The rest of the script goes on.

Waiting#

wait works in events, zones and timers. At the top level of the file, use thread:

thread(function()
	while true do
		wait(60)
		log("one more minute")
	end
end)

Important

After a wait, the player may have left. Check player:exists().

Order of a tick#

  1. received messages (movement, client events, arrivals and departures);
  2. script timers;
  3. zone entries and exits;
  4. sending to players.

If a function teleports someone, zones are evaluated again in the same tick, before anything is sent.