Runtime and state
Scripts execute on the server in Luerl, an Erlang implementation of Lua.
Scripts execute on the server in Luerl, an Erlang implementation of Lua. Each room copy has its own Lua variables and handlers. Use save and load for state that survives copies and visits. Rooms in one game share saved values.
Register handlers with on(event, function...). Registering the same event again adds a handler: every handler for an event runs, in the order registered, so the studio's generated handlers and your own share an event. Put world actions inside handlers, rather than at the top level. An ordinary handler error rolls back that handler's Lua state and effects.
on("enter", function(p)
local visits = (load(p, "visits") or 0) + 1
save(p, "visits", visits)
panel(p, "WELCOME", {{"VISITS", visits}})
window(p, {
id = "welcome",
title = "WELCOME ABOARD",
text = "Find the signal station.\nThen light the beacon.",
items = {{kind = "button", id = "begin", label = "LET'S GO"}}
})
end)
on("ui", function(p, id, value)
if id == "begin" then close(p) end
end)This page as markdown: /api/runtime-and-state.md