Implements docs/PLAIN.md sections 1-5 (the engine half of the usability pass): - core/describe.gd (Describe): rules in plain words, labelled from variable cards, collections and card inputs, falling back to the original text. - core/builder.gd (Builder): effect and condition models that round-trip with the rule text, a rule tokenizer, and known_values(board). - Collections: variable cards with var_type "collection" label their members and don't declare their stem. - Check cards (kind "check"): dice + modifier vs target, Success/Failure, chain values nat/total/effect, node "check" info, lint and static checks. - Card inputs and pipe "with" values, scoped over the pipe's subtree on the explicit work stack (OP_RESTORE frames), with defaults and snapshot evaluation. - nat on every roll-table roll; dice faces recorded through ctx.faces. - Why trace: facts on nodes and steps (input, roll, check, case, show_if, options_where, effect, when, otherwise). - StateStore rules_view setting; JSON for the new keys; LOGIC.md and PLAIN.md updated (deviations in PLAIN.md 5a). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
421 lines
26 KiB
Markdown
421 lines
26 KiB
Markdown
# TableTower — Logic Cards
|
||
|
||
**Status:** Draft spec · **Applies to:** branch `logic-cards` · **Extends:** `docs/DESIGN.md`
|
||
|
||
Plain roll tables answer "what happens?". Logic cards let a board also ask the player,
|
||
remember state, repeat steps and print a summary, so a whole procedure such as rolling a
|
||
Traveller character can run as one chain.
|
||
|
||
## 1. Card kinds
|
||
|
||
Every table has a `kind`. Existing tables are `roll`.
|
||
|
||
| Kind | What it does when the chain reaches it | Card shows |
|
||
|---|---|---|
|
||
| `roll` | Rolls an entry (weighted, or ranged with a dice expression). Unchanged, except ranged tables now accept full expressions (§4) | Entries, die button |
|
||
| `choice` | Pauses the roll and asks the player (§2) | The question and its options |
|
||
| `loop` | Runs its **Each time** entry repeatedly, then its **Afterwards** entry once (§3) | The loop rule and two rows |
|
||
| `variable` | Never rolled. Declares a variable with a type, a starting value and a description (§5) | The variable's live value |
|
||
| `sheet` | Prints its template with current values (§6) | The template, rendered live |
|
||
| `router` | Chooses the first of its cases whose condition is true (§3b) | A fork icon, one row per case with its condition |
|
||
| `check` | Rolls dice plus a modifier against a target and takes its Success or Failure result (§3c) | The roll and target, Success and Failure rows |
|
||
|
||
Every kind except `variable` can be the start of a roll and can be the target of a pipe, and
|
||
can declare **inputs** that pipes pass values to (§3d).
|
||
Every entry, of any kind, can carry **effects** (§5.2) and pipes. Pipes keep their count and
|
||
"save as" options, and a pipe count may now be an expression (`@terms`, `1d3`). A pipe may
|
||
also have a condition, or be an "otherwise" pipe (§3a).
|
||
|
||
## 2. Choice cards
|
||
|
||
A choice card pauses the chain and shows a pop-up. Its `prompt` is BBCode with `{@var}`
|
||
expansion, so a question can say "Your EDU is {@edu}. Which career?".
|
||
|
||
| `choice` | The player… | Result text | Stored as |
|
||
|---|---|---|---|
|
||
| `pick` (which option) | picks one of the card's entries, or **Random** (always offered) | the picked entry, exactly as if it had been rolled: its effects run, its text expands, its pipes follow | `save_as` (optional) gets the entry's plain text |
|
||
| `number` (how many) | types a whole number between `min` and `max` (expressions; defaults 0 and 99) | the number | `save_as`, and the chain variable `answer` |
|
||
| `text` (open ended) | types any text | the text | `save_as`, and the chain variable `answer` |
|
||
|
||
`number` and `text` cards have exactly one entry, named **Answer**. Its effects and pipes run
|
||
after the player answers, so `@terms += @answer` style bookkeeping and "go on to the next
|
||
step" pipes live there. Random on a `pick` card rolls the card normally, honouring weights
|
||
or ranges.
|
||
|
||
The pop-up also has **Cancel**, which stops the whole roll with a visible "Cancelled" marker.
|
||
Fast roll (Shift-click) still asks questions, because they are the player's decisions.
|
||
|
||
## 2a. Options from variables and conditional options
|
||
|
||
A `pick` card can build its options when the chain reaches it, from the board's variables,
|
||
and any option can be hidden when it doesn't apply. This covers "raise a skill you already
|
||
have", "convert one of your Contacts" or "the Officer table only when commissioned" without
|
||
a generated table per case.
|
||
|
||
### Options from variables
|
||
|
||
`options_from` (**Options: From variables** in the settings dialog) is one of:
|
||
|
||
| Pattern | Options |
|
||
|---|---|
|
||
| `@skill_*` (a prefix) | one per **set** board variable whose name starts with `skill_`, sorted by label. The label is the rest of the name, title-cased (`skill_gun_combat` → "Gun Combat"); the pop-up shows it with the value ("Gun Combat 2") |
|
||
| `@contacts` (a list variable) | one per comma-separated item, in list order. The label is the item |
|
||
|
||
`options_where` (**Only where**, optional) is an expression checked for every candidate, with
|
||
three chain variables bound: `option` (the variable name without `@`, such as `skill_pilot`,
|
||
or the list item), `option_label` ("Pilot") and `option_value` (the variable's value; for a
|
||
list, the item again). Only candidates for which it's true are offered, e.g.
|
||
`option_value >= 1` or `option != @last_contact`. An error counts as false for every
|
||
candidate and adds one red line ("Only where …: …") to the node.
|
||
|
||
**The Chosen entry.** A dynamic card's first entry is its **Chosen** entry (like the Answer
|
||
entry of a number card). Whichever dynamic option is picked:
|
||
|
||
1. `option`, `option_label` and `option_value` are set as chain variables (they last for the
|
||
rest of the roll, like `answer`);
|
||
2. `save_as`, if set, stores the label;
|
||
3. the Chosen entry happens like a rolled entry: its effects run, its text expands and its
|
||
pipes follow (with the snapshot rule of §3a).
|
||
|
||
The Chosen entry's text is the result text. Left as `Chosen` (the default) or empty, the result
|
||
reads as the option's label; otherwise it expands normally, e.g.
|
||
`Raised {option_label} to {@[option]}`. Indirect names (§4) let its effects change the picked
|
||
variable: `@[option] += 1`.
|
||
|
||
**Fixed extras.** Any entries after the Chosen entry are ordinary fixed options ("None of
|
||
these", "Learn something new"). They keep their own effects, text and pipes and never set
|
||
`option`. The pop-up lists the fixed options first (keys 1, 2, …), then the dynamic ones.
|
||
|
||
**Random.** Random picks among every offered option by weight: each dynamic option weighs as
|
||
much as the Chosen entry (1 unless changed), each fixed option its own weight (its range's
|
||
span on a ranged card). So three skills and a weight-2 "Something else" come up 20/20/20/40%,
|
||
and a fixed extra with weight 0 is offered to the player but never picked by Random. A plain
|
||
fixed card with nothing hidden rolls exactly as before (weights, ranges, card mode).
|
||
|
||
**No options.** When nothing is offered (no candidate passes and there are no visible fixed
|
||
options), the card doesn't ask: the node stops with a visible "No options available". A board
|
||
routes around that with a router or a conditional pipe before the card, e.g. a pipe
|
||
`when count(@skill_*) > 0`.
|
||
|
||
### Conditional options (`show_if`)
|
||
|
||
Any option of a `pick` card, fixed ones and the Chosen entry included, can have a `show_if`
|
||
expression (**Show only if**, edited under the option's row with the **if** toggle in Build
|
||
mode, or in the settings dialog). It's evaluated when the card is reached, before the pop-up
|
||
opens. When it's false the option isn't offered: not in the pop-up and not to Random, and it
|
||
never runs (a reply naming a hidden option counts as Random among the offered ones). A
|
||
`show_if` on the Chosen entry hides every dynamic option at once. An error counts as false and
|
||
adds a red line ("Show only if …: …"). If every option is hidden, the node stops with "No
|
||
options available", as above. `show_if` does nothing on other kinds (routers have their own
|
||
cases).
|
||
|
||
Examples: `@commissioned` (the Officer option), `@last_career != "Army"` (not the career you
|
||
just left), `@gold >= 10` (only when affordable).
|
||
|
||
### On the board and in previews
|
||
|
||
A dynamic card says "Options from @skill_* · where option_value >= 1" under its question,
|
||
and in Play mode how many options are available right now. Its first row is **Chosen**; fixed
|
||
rows are numbered from 1. Options with a condition show "only if …". The choice pop-up's
|
||
preview for a dynamic option names the variable behind it and shows the Chosen entry's effects
|
||
and pipes; a card preview (`TablePreview`) says "Options: each @skill_* that's set, where …".
|
||
|
||
## 3. Loop cards
|
||
|
||
A loop card has a `loop` mode and a `loop_expr` expression, plus two fixed entries:
|
||
**Each time** (index 0) and **Afterwards** (index 1).
|
||
|
||
| `loop` | Behaviour |
|
||
|---|---|
|
||
| `times` | Evaluates `loop_expr` once (e.g. `@answer`, `3`, `1d3`) and runs Each time that many times (0 is allowed) |
|
||
| `while` | Before each pass, evaluates the condition; stops when it's false |
|
||
| `until` | Runs Each time, then evaluates the condition; stops when it's true (runs at least once) |
|
||
|
||
The chain variable `i` holds the pass number (1, 2, …) during Each time. A loop's node text
|
||
reads "Repeated N times". Pipes may also form cycles (a table piping back to an earlier one).
|
||
Both are bounded only by the action limit.
|
||
|
||
## 3a. Conditional pipes
|
||
|
||
A pipe may carry `"when": "<expression>"` (shown as **Only if** in the pipe's pop-up) and/or
|
||
`"otherwise": true`. A pipe with a `when` ignores `otherwise`.
|
||
|
||
When an entry is chosen (rolled, picked, answered, a loop pass, a router case):
|
||
|
||
1. Its effects run, its text expands, and any "save as" (the pipe's that led here, or a pick
|
||
choice's `save_as`) is stored.
|
||
2. **The snapshot.** Every `when` condition and every count of the entry's pipes is worked
|
||
out once, now, before any pipe runs.
|
||
3. The pipes run in list order:
|
||
- a pipe with `when` runs only if its condition was true;
|
||
- an `otherwise` pipe runs only if none of the entry's `when` pipes was true;
|
||
- any other pipe always runs.
|
||
|
||
So an earlier pipe's subtree can change variables without changing whether, or how many
|
||
times, a later pipe on the same entry runs. Pipes are not "else if": two true conditions both
|
||
run (use a router, §3b, for first-match). Counts are only worked out for pipes that run; a
|
||
skipped pipe's count dice are never rolled.
|
||
|
||
A condition that fails to evaluate counts as false and adds a red line to the node's effect
|
||
log ("Pipe condition …: …"), the way a bad pipe count does. Only the pipes actually taken
|
||
light up after a roll. On the board, a conditional pipe has a small diamond at its source
|
||
end (hollow for otherwise) and a label such as `if @str >= 8 ×2 → foe` or `otherwise`.
|
||
|
||
**Change from earlier versions.** Pipe counts used to be evaluated lazily: the second pipe's
|
||
count was read only after the first pipe's whole subtree had run, so a branch that changed a
|
||
variable could make a later pipe fire too ("both branches fired"). Counts now come from the
|
||
snapshot. Also, a pick choice's `save_as` is now stored before the snapshot (it used to be
|
||
stored after the option's pipes were queued, which made no difference while counts were
|
||
lazy). No existing test changed.
|
||
|
||
## 3b. Router cards
|
||
|
||
A router (`kind: "router"`, "Router" in the **+ Table ▾** menu, "if / else if / otherwise")
|
||
has no dice. Its entries are **cases**, each with an entry-level `when` expression.
|
||
|
||
- When the chain reaches it, the cases are checked top to bottom and the **first** true case
|
||
is chosen. A case with an empty `when` (shown as **Otherwise**) always matches, so it
|
||
should be the last one.
|
||
- The chosen case happens exactly like a rolled entry: its effects run, its text expands and
|
||
its pipes follow (with the snapshot rule of §3a).
|
||
- If no case matches, the node stops with a visible "No case matched". A case condition that
|
||
errors counts as false and adds a red line ("Case …: …") to the node.
|
||
- It counts as one action. The node and step have `kind: "router"` and `case` (the chosen
|
||
case's index). Routers have no ranges, weights or card mode.
|
||
- A new router has two cases: "if …" (with the condition `1d6 >= 4`, to be edited) and
|
||
"Otherwise". **+ Add case** on the card adds an `if false` case before Otherwise; cases can
|
||
be reordered and removed on the card, and their conditions edited there or in the
|
||
settings dialog.
|
||
|
||
`Roller.lint_pipes(board)` lists problems for a board check (it also includes
|
||
`lint_check()` and `lint_inputs()`, §3c and §3d): `when` or case conditions that
|
||
don't parse, bad `options_from` patterns, `options_where` and `show_if` expressions that don't
|
||
parse, `options_from`/`show_if` on cards where they do nothing (§2a), an otherwise pipe listed before a `when` pipe on the same entry (a hint: it still
|
||
works), an otherwise pipe on an entry with no `when` pipe (it always runs), and routers with
|
||
no cases or whose Otherwise case isn't last. Each item is `{table_id, entry_id, message}`; items
|
||
from the check and input lint also carry `kind` (`"check"` or `"inputs"`) and `level`
|
||
(`"error"` or `"hint"`), which `BoardTester.static_checks()` passes on.
|
||
|
||
## 3c. Check cards
|
||
|
||
A check (`kind: "check"`) rolls `check_dice` (default `2d6`), adds `check_mod` (an expression,
|
||
default empty, e.g. `dm(@str)`) and compares the total with `check_target` (an expression,
|
||
default `8`): with `check_cmp` `ge` (the default) it succeeds when the total is the target or
|
||
more, with `le` (roll-under) when it is the target or less. It has two fixed entries,
|
||
**Success** (index 0) and **Failure** (index 1); the matching one happens like a rolled entry
|
||
(effects, text, pipes with the §3a snapshot).
|
||
|
||
- Before that entry runs, three chain variables are set: `nat` (the dice alone), `total`
|
||
(dice plus modifier) and `effect` (total minus target; negative on a roll-under success).
|
||
- The node and step have `kind: "check"`, `value` (the total) and
|
||
`check: {nat, mod, total, target, success}`. It counts as one action.
|
||
- A dice, modifier or target expression that fails, or gives text, stops the node with
|
||
"Can't roll the check: …" (a dead end in the board test). A check with no Failure entry
|
||
stops with "This check has no Failure result" when it fails.
|
||
- `Roller.check_roll(table, ctx)` does the roll alone; `Roller.lint_check(table)` reports
|
||
expressions that don't parse, an empty dice or target, and a missing Success or Failure entry.
|
||
|
||
### `nat` on roll tables
|
||
|
||
Every roll of a `roll` table sets the chain variable `nat` too: for a ranged table, the sum of
|
||
the dice faces without any modifier (`2d6 + dm(@str)` and `2d6+3` both give the 2d6 alone), so a
|
||
"natural 2" rule can test `nat = 2`; for a weighted or card-mode table, the die value. An
|
||
expression with no dice at all (`@terms`) leaves `nat` as it was. A pick card's Random never
|
||
sets it.
|
||
|
||
## 3d. Card inputs (pipe parameters)
|
||
|
||
Any card (not a variable card) may declare `inputs: [{name, label, default}]`, and a pipe object
|
||
may pass values with `"with": {"<name>": "<expression>"}`.
|
||
|
||
- The `with` expressions are worked out in the entry's snapshot (§3a), together with the pipe's
|
||
condition and count, so an earlier pipe's subtree can't change them; a pipe with a count
|
||
passes the same values on every roll.
|
||
- When the chain reaches the card, each input becomes a chain variable (`tier`, `{tier}` in
|
||
text) for the card's whole subtree: its entry's effects, text, inline references and pipes,
|
||
loop passes, router cases and choice options. When that subtree ends, the previous values
|
||
(or their absence) come back. Two pipes into the same card can pass different values.
|
||
- An input the pipe doesn't pass gets its `default`, an expression worked out when the card is
|
||
reached (quote text: `"High"`; empty means 0). A roll that starts on the card, an inline
|
||
`[[reference]]` to it, and a pipe without `with` all use the defaults.
|
||
- A `with` value whose expression fails is left out (so the default applies) and adds a red
|
||
line "Pipe input tier = …: …"; a default that fails gives 0 and a red line. A `with` name
|
||
the target doesn't declare is still passed, as a chain variable.
|
||
- The node and step carry `inputs: {name: value}`.
|
||
- `Roller.lint_inputs(board, table)` reports input names that aren't names or are declared
|
||
twice and defaults or `with` expressions that don't parse (errors), and a `with` naming an
|
||
input the target doesn't declare (a hint).
|
||
- This works on the roller's explicit work stack (an `OP_RESTORE` frame under the subtree), so
|
||
it needs no recursion and respects the 10,000-action limit; a halted roll still puts the
|
||
values back.
|
||
|
||
## 4. Expressions
|
||
|
||
Expressions appear in loop rules, pipe counts, pipe conditions, router cases, `min`/`max`,
|
||
dice fields and effects. They are
|
||
evaluated with Godot's `Expression`, after a small rewrite.
|
||
|
||
- **Numbers and text:** `12`, `-3`, `"Aslan"`
|
||
- **Operators:** `+ - * / %`, comparisons `= == != < <= > >=` (a lone `=` in a condition means
|
||
equals), `and or not` (also `&& || !`), parentheses, and `in` for "text contains".
|
||
- **Variables:**
|
||
- `@name` reads a board variable (§5). If it's unset, it reads as `0` in arithmetic and as
|
||
`""` next to text.
|
||
- `@[expr]` reads the board variable **named by** `expr` (an indirect name), e.g.
|
||
`@[option]` or `@["skill_" + option]`. The computed name is lowercased and a leading `@`
|
||
is dropped; it must then be lowercase letters, digits and `_` (not starting with a
|
||
digit), or the expression fails with "@[…] gave "Old Bill", which isn't a variable name".
|
||
Unset reads as `0` (or `""` next to text), like `@name`.
|
||
- A bare `name` reads a chain variable (`answer`, `i`, or anything saved with `-> name`).
|
||
- **Dice:** `2d6`, `d20`, `3D`, `D3`, `2D`. A missing count means 1, and missing sides mean 6, so
|
||
`2D` is 2d6. Every die in an expression is rolled fresh.
|
||
- **Functions:** `min max clamp abs floor ceil round`, plus:
|
||
- `dm(x)`: the 2D-game characteristic modifier. It gives -3 for 0, -2 for 1–2, -1 for 3–5,
|
||
0 for 6–8, +1 for 9–11, +2 for 12–14, and +3 for 15 or more.
|
||
- `has(list, item)`: whether a comma-separated list contains an item.
|
||
- `count(prefix)`: the number of set variables whose names start with `prefix`.
|
||
- `if(condition, then, else)`: picks a value. Both branches are evaluated, so dice in
|
||
either are rolled. The inline `a if c else b` form is refused, because Godot's
|
||
Expression returns the wrong branch for it.
|
||
|
||
Ranged `roll` tables keep plain dice (`2d6`) and also accept any expression, such as
|
||
`2d6 + dm(@end)` or `@terms`. Values beyond the lowest or highest range clamp to that range,
|
||
so a check table only needs "2–6 fail" and "7–12 pass". The card labels the ends `≤6` and `7+`
|
||
when the expression has modifiers.
|
||
|
||
## 5. Variables
|
||
|
||
### 5.1 Board variables (`@name`)
|
||
- They belong to the collection and are kept between rolls in local state, never exported.
|
||
Values are numbers or text.
|
||
- Names are lowercase letters, digits and `_`. A variable exists once it's assigned; no
|
||
declaration is needed. A **variable card** (`kind: variable`) is optional and gives a
|
||
variable a label, a type (`number`, `text` or `list`), a starting value (an expression) and
|
||
details.
|
||
- A **collection** is a variable card with `var_type: "collection"`. Its `var_name` is a stem
|
||
(`skill`), its name the group's label ("Skills"), and its members are the board variables
|
||
`@<stem>_<item>` (`@skill_gun_combat`). It declares no variable of its own: members are
|
||
ordinary variables, `reset @skill_*`, `count("skill_")`, `{@skill_*}` and
|
||
`options_from: "@skill_*"` work as before, and plain descriptions (`Describe`, docs/PLAIN.md)
|
||
label members by the rest of their name ("Gun Combat") and the group by the card's name.
|
||
`RollTable.create("variable", id, "Skills", "collection")` gives the stem `skill` (the name's
|
||
slug without a final "s"). Its live display lists the set members.
|
||
- `reset @name` sets a declared variable back to its starting value, or deletes an undeclared
|
||
one. `reset @skill_*` resets every variable with that prefix.
|
||
- Chain variables (no `@`, e.g. `answer`, `i`, `-> hero`) last for one top-level roll, as
|
||
before.
|
||
|
||
### 5.2 Effects
|
||
An entry's `effects` field holds statements, one per line or separated by `;`. They run when
|
||
the entry is chosen (rolled, picked or answered), before its text expands and its pipes
|
||
follow.
|
||
|
||
```
|
||
@str = 2d6 set
|
||
@terms += 1 add (number) · append ", item" if not present (text/list)
|
||
@credits -= 1000 subtract (number) · remove the item (text/list)
|
||
@age *= 2 multiply (/= divides, rounding down)
|
||
@skill_pilot += 1 unset counts as 0, so this gives Pilot 1 or raises it
|
||
@skill_vacc_suit = max(@skill_vacc_suit, 0) gain at level 0
|
||
@traits += "Psionic"
|
||
reset @skill_*
|
||
@[option] += 1 the variable named by option (indirect)
|
||
@["skill_" + option] = max(@["skill_" + option], 0)
|
||
reset @[option]
|
||
```
|
||
|
||
An indirect target `@[expr]` is worked out when the statement runs. A bad expression or a
|
||
computed name that isn't a valid variable name is a red effect line, and nothing is written.
|
||
|
||
Each statement that runs is listed under its step in the result tray (e.g. "STR = 9"). A bad
|
||
statement shows a red marker in the tray and in Build mode rather than stopping the roll.
|
||
|
||
### 5.3 Text
|
||
- `{@name}` shows a value. If it's unset, it shows the `{@name?}` marker.
|
||
- `{@skill_*}` lists every set variable with that prefix, sorted, as `Gun Combat 1, Pilot 0`.
|
||
The name after the prefix is title-cased, with `_` read as a space.
|
||
- `{= expr}` shows a computed value, e.g. `STR {@str} ({= dm(@str)})`.
|
||
- `{@[expr]}` shows the variable named by `expr`, e.g. `{@[option]}`; unset shows its
|
||
`{@name?}` marker, a bad name an error marker.
|
||
- The existing `{@var|Table}`, `{hero}` and `[[refs]]` work as before.
|
||
|
||
## 6. Sheet cards
|
||
A sheet card holds one template (its single entry's text, multi-line BBCode). On the board it
|
||
always shows the template rendered with current values, so a character sheet stays up to
|
||
date while the chain runs. When the chain reaches it, the rendered template becomes that
|
||
step's result.
|
||
|
||
## 7. Limits
|
||
- **Actions:** one top-level roll may take at most **10,000 actions**. One action is a table
|
||
being rolled or answered, a router choosing a case, or one loop pass. Past that, the roll stops with "Stopped after
|
||
10,000 actions", and everything up to that point is kept.
|
||
- **Inline references:** `[[refs]]` inside text still nest at most 32 deep.
|
||
- **Picks:** a dynamic option counts the same single action as any pick.
|
||
- **Implementation:** pipes and loops must not use GDScript recursion proportional to chain
|
||
length. Long chains (thousands of steps) must not overflow the call stack. That applies to
|
||
the roller and to everything that walks a result (flatten, lighting, history).
|
||
|
||
## 8. Rolling, prompts and display
|
||
- The roller is a coroutine. It `await`s `ctx.prompt.call(request)` whenever a choice card is
|
||
reached. With no prompt hook (tests, headless), `pick` chooses Random, `number` answers
|
||
`min`, and `text` answers `""`.
|
||
- **Request:** `{table_id, kind, prompt, options: [{index, entry, text, details, weight}], min,
|
||
max, default, log, hidden}`. A pick's options are only the offered ones (§2a): fixed
|
||
options have `index` = `entry` = the entry's index; dynamic ones have `index` =
|
||
entries count + their position, `entry` 0 (the Chosen entry) and `dynamic`, `option`,
|
||
`label`, `value` and `value_text`. `log` holds `show_if`/`options_where` error lines and
|
||
`hidden` counts fixed options `show_if` hid. Replies must be one of the offered indices
|
||
(or -1); the UI and `BoardTester.answer()` both pick from `options`.
|
||
- **Reply:** `pick` returns an entry index or `-1` for Random. `number` returns an int.
|
||
`text` returns a String. `null` means Cancel.
|
||
- In the UI, when a prompt is needed, the steps so far appear instantly (lit on the board and
|
||
in the tray) before the pop-up opens, so the player can see what led to the question.
|
||
After the last answer the rest of the roll is shown at once. A roll with no questions
|
||
animates as before, unless it's long (more than 40 steps), when it shows at once.
|
||
- The tray shows the last 12 steps of a long chain behind a "+N earlier steps" note. If the
|
||
chain reached a sheet card, the result headline is that sheet.
|
||
|
||
## 9. File format additions
|
||
Table keys:
|
||
- `kind` (`roll` is the default and is omitted; `check` is a check card)
|
||
- `choice`, `prompt`, `save_as`, `min`, `max` (choice cards)
|
||
- `options_from`, `options_where` (pick choices with options from variables, §2a)
|
||
- `loop`, `loop_expr` (loop cards)
|
||
- `var_name`, `var_type` (`number`, `text`, `list` or `collection`), `initial` (variable cards)
|
||
- `check_dice`, `check_mod`, `check_cmp` (`ge` or `le`), `check_target` (check cards; Strings,
|
||
left out at their defaults `2d6`, `""`, `ge`, `8`)
|
||
- `inputs`: `[{"name": "tier", "label": "Tier", "default": "1"}]` (any card; `label` and
|
||
`default` left out when empty)
|
||
|
||
Entry keys:
|
||
- `effects` (String)
|
||
- `when` (String, router cases; empty or missing is Otherwise)
|
||
- `show_if` (String, pick options; empty or missing is always shown)
|
||
|
||
Pipe objects may have `"count": "<expression>"`, `"when": "<expression>"`,
|
||
`"otherwise": true` (left out when the pipe has a `when`) and
|
||
`"with": {"<input name>": "<expression>"}` (§3d).
|
||
|
||
## 10. Why trace
|
||
|
||
Every node may carry `why`: an Array of facts, plain Dictionaries recorded by the roller, so a
|
||
UI can say why a roll went the way it did (`Describe.why(fact, board, plain)` turns one into a
|
||
sentence). Steps from `Roller.flatten()` carry them (a copy of the array) and they survive JSON,
|
||
so history keeps them. The key is left out when a node has no facts. Each fact has a `type`:
|
||
|
||
| `type` | On | Keys |
|
||
|---|---|---|
|
||
| `input` | the card's node, first | `name`, `value`, `from` (`"pipe"` or `"default"`) |
|
||
| `roll` | rolled nodes (roll tables, a pick's plain Random) | `pick` (`"dice"`, `"weighted"`, `"card"`), `dice`, `total`; dice rolls also `faces` (Array), and when there were dice `nat` and `mod` |
|
||
| `check` | check nodes | `dice`, `mod_expr`, `target_expr`, `faces`, `nat`, `mod`, `total`, `target`, `cmp`, `success` |
|
||
| `case` | router nodes, one per case tried | `index`, `expr` (`""` for Otherwise), `values`, `result`, `error`? |
|
||
| `show_if` | pick nodes when options were hidden | `hidden` (fixed options hidden), `chosen_hidden` |
|
||
| `options_where` | dynamic pick nodes with a filter | `from`, `expr`, `kept`, `total` |
|
||
| `effect` | any node whose entry has effects, one per statement that ran | `var` (the real target, `@[…]` resolved), `op` (`=`, `+=`, `-=`, `*=`, `/=`, `reset`), `before`, `after` (null when unset); a prefix reset has `count` instead |
|
||
| `when` | the node whose entry has the pipe, one per conditional pipe | `to` (table id), `expr`, `values`, `result`, `error`? |
|
||
| `otherwise` | likewise, one per otherwise pipe | `to`, `result` |
|
||
|
||
`values` maps each variable the expression reads (`"@luck"`, or a chain name such as `"tier"`) to
|
||
its value when it was evaluated (null when unset); indirect `@[…]` names aren't listed. The
|
||
order on a node is: input facts, then roll/check/case/options facts, then effects, then
|
||
when/otherwise facts.
|