Bus
The one table the game's parts talk over. **Every slice announces what happened and listens for what it cares about; no slice requires another**, and this is the table in the middle they share.
game.Bus
The one table the game's parts talk over. Every slice announces what happened and listens for what it cares about; no slice requires another, and this is the table in the middle they share.
local Bus = require("game.Bus")
Bus.emit(Bus.E.noise, { id = "sprint", position = p, source = "player" })
local handle = Bus.on(Bus.E.playerCaught, function(payload)
print(payload.monster) -- "resident"
end)
Bus.off(Bus.E.playerCaught, handle)
Bus.E is the event-name list, spelled once so no slice can invent a string
nobody else listens for. It is the same set as GameRules.EVENTS, which also
documents the payload each event carries; the scene entrypoint checks the two
agree on every load and warns if they have drifted.
on, once, off, emit, count, clear, plus error() and clearError()
for the last handler failure.
Two rules, because getting them wrong desynchronises a co-op run
- The bus is local. It is a module, and a module is one instance per
peer. An emit reaches the parts of the game running on this machine and
nowhere else. Anything another player must agree about — a door, a key, the
objective list, the monster — is written to the shared store
(
runtime_data.world, under the keys inGameRules.DATA) and read back by every peer. Emit the local response to a thing; store the fact of it. A part that emitsdoorOpenedand never writes the store has a door that opens for one player and stays shut for everyone else. - An emit is synchronous. Handlers run before
emitreturns, in subscription order, on the frame the thing happened. The payload table is handed out, not copied — read it, do not keep it, do not mutate it. A handler that throws is caught and reported, so one broken listener cannot silence every other listener on the same event;Bus.error()reads the last one back.
Who calls it: every slice. The house emits doors and pickups, the monsters emit their state and a sighting, the survival systems emit noise, damage and clues, the interface listens to most of it, and the audio director listens to nearly all of it.
Scoped to this part · feeds back into the world's score.