WikilyWIKILY
All games8 Wikis · pick your game
Menu

Documentation

Writing Lua scripts

Updated 2026-07-24

A Formula variable usually holds a one-line calculation. When the answer needs several steps, a loop or a lookup, that same variable can hold a small Lua script instead.

When to reach for Lua

A script is a variable like any other. It computes its value instead of holding one, and you edit it in the browser.
Plain formulaOne expression, one answer: roundUp(dodo.hp / 5).Covers most day-to-day math.
Lua scriptSeveral steps, a loop over a list, or a lookup.When one line will not do it.

To switch, open the variable and choose Lua script instead of Formula. Everything else stays the same: same name, same {{ }} token on the page.

Reading other variables

A script reads every other variable through a table named vars, and must end with a return. Whatever you return is what the variable becomes.

In a formuladodo.hp
In Luavars.dodo.hp
A whole scriptreturn math.ceil(vars.dodo.hp / 5)

That is standard Lua. The usual libraries are there: math.*, string.*, and helpers like ipairs and tonumber.

Returning several fields

A script can return a whole table of named fields at once. A token then reads one field at a time with a dot, exactly like a Row link variable.

The scriptreturn { food = (vars.level or 1) * 5, effectiveness = 98.7 }
On the page{{ tame.food }} and {{ tame.effectiveness }}
A reader sees5 and 98.7

vars.level or 1 is a safety net. If level has no value yet, or 1 steps in so the math still works. Guard anything that might be missing.

The Lua editor

Picking Lua script turns the plain field into a real code editor with syntax highlighting. Two controls sit above it.

FormatRe-indents the whole script. Rescues one that has drifted.
ExpandOpens fullscreen. Close it again and your work is still there.

Which variables a script can see

The vars table holds every variable in scope where the script lives, not every variable on the wiki.

On the Variables pageSees the wiki's variables.
On a pageAlso sees that page's own.
Inside a boxAlso sees the box's own.

A script can always read outward, never inward. Where a name exists twice the innermost wins, and vars.wiki.name still reaches the wiki-level value.

Keep a script on the page that uses it. Only that page runs it, only that page ships it to the browser, and it goes through ordinary page review instead of needing wiki-wide rights.

The sandbox and safety

A script always runs in the same locked-down sandbox under the same short time limit, whether on the server or in a reader’s browser. The rules never change between the two.

No outside worldNo files, no network. io, os and require are removed before your script runs.
Nothing but varsA script reaches only the values handed to it.
Failure is blankToo slow or broken resolves to nothing, the same fallback every other variable gets.

When it recomputes live

A script resolves on the server once when the page loads, so the page always arrives with a real value in place. No waiting, no flicker.

A script that reads a Reader input, directly or through another variable, also reruns in the reader browser every time that input changes. No page reload.

The tame example does this because it reads vars.level. Drag the level control and {{ tame.food }} recomputes to match.

None of this costs a page that does not use it. The Lua engine downloads only on a page that actually runs a live script.

Next steps