The API
Every layer talks to the game through Variations, and it deals in five kinds
of thing. The runtime stores them and checks who may change them. The root's
own script gives them meaning, by reading the rules and building the zones,
items and slots.
| Kind | What it is | Change or add it | Read or use it | The point that guards it |
|---|---|---|---|---|
| Rule | A named value, such as player.speed | set_rule(key, value) | rule(key, fallback), rules() | rules.<key> |
| Zone | A function that builds a piece of the world | register_zone(name, build) | zones() | zones, all of them or none |
| Item | A function that builds one thing to place, such as a coin | register_item(name, build) | make_item(name), items() | items, all of them or none |
| Slot | The one thing the root asks for by name, such as the player | fill_slot(name, build) | slot(name) | slots.<name> |
| Event | A name and a payload, sent to every layer | emit_event(name, payload) | connect to the event signal | nothing: events are open to all |
A point is the name the runtime checks before a change: rules.sky.time,
zones, slots.player. The root's open list and every layer's seal list
are lists of points.
Yes or no
A call that changes something returns true when it took effect and false
when it was refused. A refusal is not an error. The game keeps running and the
refusal is listed in the game's report under denied.
if not Variations.set_rule("world.gravity", 6.0):
Variations.emit_event("hud.message", {"text": "Gravity is sealed here"})
Looking before you act
| Call | What it tells you |
|---|---|
allowed(point) | Whether your layer may change that point, for example allowed("rules.sky.time") |
is_root_layer() | Whether your layer is the root |
credits() | Who made each layer, root first |
Signals
event(name, payload)fires for every event any layer sends.rule_changed(key, value)fires whenever a rule is set, so a root can react to a child's change without checking over and over.
Those calls and signals are the whole API. The Reference lists each one with its arguments.
A layer's life
- The runtime loads each layer's files, root first.
- It runs each layer's entry script once, in the same order. This is where
you call
set_rule,register_zoneand the rest, usually in_ready. - When every layer has run, the runtime sends the
startevent. The root builds the world from the zones, items and slots it now has. - The game plays. Layers hear events and send their own.
Starter World sends world.ready when it has finished building, which is the
first moment the player and the world exist.