Errors and limits
Handle unavailable game values, script limits, and errors.
Return and error pattern
Many calls return a result on success or nil, error on failure. A valid false result is different from nil:
local level, err = game.local_level()
if level == nil then
log.warn(err)
else
log.info("Level " .. level)
endGame information may be unavailable while loading or changing characters. Read it again when your script needs it.
Script limits
| Limit | Current value |
|---|---|
| Lua memory per script | 256 MiB |
| Callback execution | 40,000,000 instructions |
| Worker resume | 10,000,000 instructions |
| Source file | 8 MiB |
| Running modules | 32 |
| Per-script rotating log | 1 MiB, previous copy in .log.1 |
| HTTP response | 64 KiB; 10-second timeout |
You can use the base, coroutine, table, string, math, and utf8 Lua libraries, plus os.clock() and os.time(). Other os functions, dofile, loadfile, load, and collectgarbage are unavailable. Import local and shared Lua files with require. os.clock() measures process CPU time rather than elapsed time.
Execution has no CPU-time or elapsed-time deadline. Instruction limits still stop runaway Lua loops. Keep long jobs cooperative so your script returns control regularly.
Coroutines run in the same script state and share the current callback's execution and memory limits. Yielding does not reset those limits within the callback. Uncached and nested require chunks also share their caller's consumed instructions; importing a library does not grant a fresh budget. Resume a cooperative job on a later tick for a fresh callback budget. script.sleep() remains restricted to the single worker created by script.start_worker(); use coroutine.yield() for jobs resumed manually from on_tick.
Lua traceback text appears in the Scripts tab and the matching logs/instant_<id>.log or logs/module_<id>.log. log.info, log.warn, and log.error write timestamped lines to that file and the console.
Calls that need the game may return nil, error when your character or world is unavailable. Check results before drawing, logging, or acting on them.