rpgdesk.js creates the global RPGDesk object. Almost everything returns a Promise: use await or
.then(). Calls made before connecting wait for the connection. To learn with examples, see
JavaScript on the sheet and Rolls, chat and card.
the value: text, number, true/false, an object (group) or undefined. doc.get('') gives the whole document
doc.set(path, value)
writes. An object writes field by field; null deletes. Returns a promise
doc.update({ path: value, … })
writes several fields in one batch
doc.batch(() => { … })
whatever is written inside the function goes in a single batch, applied whole or refused whole
doc.watch(path, fn, { now })
tells you about each change on the path or inside it: fn(value, { local }). Returns the function that stops it
doc.compute(target, [sources], fn)
computed field: writes fn(...source values) to the target when a source changes in this browser, if the person can write to the target. undefined does not write. Returns the function that stops it
doc.canWrite(path)
whether the person can write there
doc.list(path)
the list at the path (see below)
doc.restrict(path, 'gm' | 'owner' | null)
game masters only: the part becomes game master only, owner and game masters only, or everyone’s again
doc.on('rejected', fn)
tells you when a write is refused: fn(message). Returns the function that stops it
Paths are texts ('hp.current') or arrays (['npcs', '#' + id, 'hp']); #id points to a list
item.
rolls in the room (with the 3D dice, in everyone’s chat). Returns { expression, total, items, successes }
RPGDesk.chat.send(text, { kind, name })
sends to the chat. kind: 'chat', 'action', 'laugh', 'narrator' or 'npc' (with name)
RPGDesk.chat.local(text)
a line in the chat of whoever is looking only
A roll’s items: { kind: 'dice', sign, faces, results }, { kind: 'fudge', sign, results } or
{ kind: 'value', sign, value }. successes only exists in rolls with >.