Logic cards engine: expressions, effects, choice/loop/variable/sheet cards, coroutine roller
- Expr: @vars, chain vars, dice tokens, dm/has/count, lone = as ==, errors as values, parse cache
- Effects: = += -= *= /= and reset (with prefix), number vs list semantics, logs, validation
- RollTable kinds and per-kind fields with factories; expression dice with end clamping
- TableEntry effects and expression pipe counts; JSON round trip through JsonIO
- TextExpander: {@prefix_*}, {= expr}, number display, expand_async and live render()
- Roller: coroutine with an explicit work stack, prompts for choice cards, loops,
10,000-action limit, partial tree on ctx.root, iterative flatten/collect_lit
- Variables keep numbers as numbers through StateStore
- Main: awaits the roll with a default (headless) prompt hook, iterative playback,
long chains show at once
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 13:38:42 -06:00
|
|
|
|
class_name Effects
|
|
|
|
|
|
extends RefCounted
|
|
|
|
|
|
## Effect statements on entries (docs/LOGIC.md §5.2): one per line or
|
|
|
|
|
|
## separated by ";".
|
|
|
|
|
|
##
|
|
|
|
|
|
## @str = 2d6 set
|
|
|
|
|
|
## @terms += 1 add a number, or append ", item" to text/list if absent
|
|
|
|
|
|
## @credits -= 1000 subtract a number, or remove the item from text/list
|
|
|
|
|
|
## @age *= 2 multiply (/= divides, rounding down)
|
|
|
|
|
|
## reset @name back to the variable card's starting value, or deleted
|
|
|
|
|
|
## reset @skill_* every variable with that prefix
|
Dynamic pick options, show_if and indirect @[expr] names
Pick choice cards can take their options from variables (options_from:
@prefix_* or a @list, filtered by options_where with option, option_label
and option_value bound). A Chosen entry runs for whichever dynamic option
is picked; fixed entries stay as extras, listed first. Random weighs each
dynamic option as the Chosen entry and fixed ones by weight. Any pick
option can have show_if, which hides it from the pop-up and from Random;
with nothing offered the node stops with "No options available".
@[expr] reads or writes the variable named by expr in expressions,
effects (including reset) and text ({@[expr]}); bad computed names are
effect errors. JSON round trip, lint_options in lint_pipes, choice
pop-up value badges and previews, card and settings UI, docs, demo board
(Spend a find) and tests/test_options.gd.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 18:55:38 -06:00
|
|
|
|
## @[expr] += 1 the variable named by expr (indirect), e.g.
|
|
|
|
|
|
## @[option] += 1, reset @["skill_" + option]
|
Logic cards engine: expressions, effects, choice/loop/variable/sheet cards, coroutine roller
- Expr: @vars, chain vars, dice tokens, dm/has/count, lone = as ==, errors as values, parse cache
- Effects: = += -= *= /= and reset (with prefix), number vs list semantics, logs, validation
- RollTable kinds and per-kind fields with factories; expression dice with end clamping
- TableEntry effects and expression pipe counts; JSON round trip through JsonIO
- TextExpander: {@prefix_*}, {= expr}, number display, expand_async and live render()
- Roller: coroutine with an explicit work stack, prompts for choice cards, loops,
10,000-action limit, partial tree on ctx.root, iterative flatten/collect_lit
- Variables keep numbers as numbers through StateStore
- Main: awaits the roll with a default (headless) prompt hook, iterative playback,
long chains show at once
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 13:38:42 -06:00
|
|
|
|
##
|
|
|
|
|
|
## A target without "@" is a chain variable. Unset counts as 0 (or "" when the
|
|
|
|
|
|
## value added is text). run() never stops on a bad statement: it logs an error
|
|
|
|
|
|
## line and carries on.
|
|
|
|
|
|
|
|
|
|
|
|
const OPS := ["+=", "-=", "*=", "/=", "="]
|
|
|
|
|
|
|
2026-11-11 09:06:55 -06:00
|
|
|
|
|
|
|
|
|
|
## A comma-separated list with `item` added at the end (unless it's there
|
2026-11-14 13:40:20 -06:00
|
|
|
|
## already, ignoring capitals; with `repeats`, every time) or, with `remove`,
|
|
|
|
|
|
## taken out (the first match). Returns the new list text. Used by += / -= on
|
|
|
|
|
|
## lists and by saving a result into a list value (RollContext.save_result()).
|
|
|
|
|
|
static func list_with(list: Variant, item: String, remove: bool = false, repeats: bool = false) -> String:
|
2026-11-11 09:06:55 -06:00
|
|
|
|
var items := Expr.list_items(list if list != null else "")
|
|
|
|
|
|
var at := -1
|
|
|
|
|
|
for k in items.size():
|
|
|
|
|
|
if items[k].to_lower() == item.to_lower():
|
|
|
|
|
|
at = k
|
|
|
|
|
|
break
|
2026-11-14 13:40:20 -06:00
|
|
|
|
if not remove and (at < 0 or repeats) and item != "":
|
2026-11-11 09:06:55 -06:00
|
|
|
|
items.append(item)
|
|
|
|
|
|
elif remove and at >= 0:
|
|
|
|
|
|
items.remove_at(at)
|
|
|
|
|
|
return ", ".join(items)
|
|
|
|
|
|
|
Logic cards engine: expressions, effects, choice/loop/variable/sheet cards, coroutine roller
- Expr: @vars, chain vars, dice tokens, dm/has/count, lone = as ==, errors as values, parse cache
- Effects: = += -= *= /= and reset (with prefix), number vs list semantics, logs, validation
- RollTable kinds and per-kind fields with factories; expression dice with end clamping
- TableEntry effects and expression pipe counts; JSON round trip through JsonIO
- TextExpander: {@prefix_*}, {= expr}, number display, expand_async and live render()
- Roller: coroutine with an explicit work stack, prompts for choice cards, loops,
10,000-action limit, partial tree on ctx.root, iterative flatten/collect_lit
- Variables keep numbers as numbers through StateStore
- Main: awaits the roll with a default (headless) prompt hook, iterative playback,
long chains show at once
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 13:38:42 -06:00
|
|
|
|
static var _stmt_re: RegEx = null
|
|
|
|
|
|
static var _reset_re: RegEx = null
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## Splits effect text into statements: lines, and ";" outside quotes. Empty
|
|
|
|
|
|
## statements are dropped.
|
|
|
|
|
|
static func split(text: String) -> Array[String]:
|
|
|
|
|
|
var out: Array[String] = []
|
|
|
|
|
|
var cur := ""
|
|
|
|
|
|
var quote := ""
|
|
|
|
|
|
for c in text:
|
|
|
|
|
|
if quote != "":
|
|
|
|
|
|
cur += c
|
|
|
|
|
|
if c == quote:
|
|
|
|
|
|
quote = ""
|
|
|
|
|
|
elif c == "\"" or c == "'":
|
|
|
|
|
|
quote = c
|
|
|
|
|
|
cur += c
|
|
|
|
|
|
elif c == ";" or c == "\n":
|
|
|
|
|
|
if cur.strip_edges() != "":
|
|
|
|
|
|
out.append(cur.strip_edges())
|
|
|
|
|
|
cur = ""
|
|
|
|
|
|
else:
|
|
|
|
|
|
cur += c
|
|
|
|
|
|
if cur.strip_edges() != "":
|
|
|
|
|
|
out.append(cur.strip_edges())
|
|
|
|
|
|
return out
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## Parses one statement. Returns {src, op ("=", "+=", "-=", "*=", "/=" or
|
|
|
|
|
|
## "reset"), target ("@name", "name", or "@prefix_*" for reset), expr} or
|
|
|
|
|
|
## {src, error}.
|
|
|
|
|
|
static func parse_statement(src: String) -> Dictionary:
|
|
|
|
|
|
_compile()
|
|
|
|
|
|
var s := src.strip_edges()
|
Dynamic pick options, show_if and indirect @[expr] names
Pick choice cards can take their options from variables (options_from:
@prefix_* or a @list, filtered by options_where with option, option_label
and option_value bound). A Chosen entry runs for whichever dynamic option
is picked; fixed entries stay as extras, listed first. Random weighs each
dynamic option as the Chosen entry and fixed ones by weight. Any pick
option can have show_if, which hides it from the pop-up and from Random;
with nothing offered the node stops with "No options available".
@[expr] reads or writes the variable named by expr in expressions,
effects (including reset) and text ({@[expr]}); bad computed names are
effect errors. JSON round trip, lint_options in lint_pipes, choice
pop-up value badges and previews, card and settings UI, docs, demo board
(Spend a find) and tests/test_options.gd.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 18:55:38 -06:00
|
|
|
|
var ind := _parse_indirect(s)
|
|
|
|
|
|
if not ind.is_empty():
|
|
|
|
|
|
return ind
|
Logic cards engine: expressions, effects, choice/loop/variable/sheet cards, coroutine roller
- Expr: @vars, chain vars, dice tokens, dm/has/count, lone = as ==, errors as values, parse cache
- Effects: = += -= *= /= and reset (with prefix), number vs list semantics, logs, validation
- RollTable kinds and per-kind fields with factories; expression dice with end clamping
- TableEntry effects and expression pipe counts; JSON round trip through JsonIO
- TextExpander: {@prefix_*}, {= expr}, number display, expand_async and live render()
- Roller: coroutine with an explicit work stack, prompts for choice cards, loops,
10,000-action limit, partial tree on ctx.root, iterative flatten/collect_lit
- Variables keep numbers as numbers through StateStore
- Main: awaits the roll with a default (headless) prompt hook, iterative playback,
long chains show at once
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 13:38:42 -06:00
|
|
|
|
var m := _reset_re.search(s)
|
|
|
|
|
|
if m != null:
|
|
|
|
|
|
var target := "@" + m.get_string(1).to_lower() + m.get_string(2)
|
|
|
|
|
|
return {"src": s, "op": "reset", "target": target, "expr": ""}
|
|
|
|
|
|
if s.to_lower().begins_with("reset"):
|
|
|
|
|
|
return {"src": s, "error": "Write reset @name or reset @prefix_*"}
|
|
|
|
|
|
m = _stmt_re.search(s)
|
|
|
|
|
|
if m == null:
|
|
|
|
|
|
return {"src": s, "error": "Not a statement; try @name = value"}
|
|
|
|
|
|
var t := m.get_string(1)
|
|
|
|
|
|
if t.begins_with("@"):
|
|
|
|
|
|
t = t.to_lower()
|
|
|
|
|
|
var expr := m.get_string(3).strip_edges()
|
|
|
|
|
|
if expr == "":
|
|
|
|
|
|
return {"src": s, "error": "Nothing after %s" % m.get_string(2)}
|
|
|
|
|
|
return {"src": s, "op": m.get_string(2), "target": t, "expr": expr}
|
|
|
|
|
|
|
|
|
|
|
|
|
Dynamic pick options, show_if and indirect @[expr] names
Pick choice cards can take their options from variables (options_from:
@prefix_* or a @list, filtered by options_where with option, option_label
and option_value bound). A Chosen entry runs for whichever dynamic option
is picked; fixed entries stay as extras, listed first. Random weighs each
dynamic option as the Chosen entry and fixed ones by weight. Any pick
option can have show_if, which hides it from the pop-up and from Random;
with nothing offered the node stops with "No options available".
@[expr] reads or writes the variable named by expr in expressions,
effects (including reset) and text ({@[expr]}); bad computed names are
effect errors. JSON round trip, lint_options in lint_pipes, choice
pop-up value badges and previews, card and settings UI, docs, demo board
(Spend a find) and tests/test_options.gd.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 18:55:38 -06:00
|
|
|
|
## An indirect statement ("@[expr] op value" or "reset @[expr]"), parsed into
|
|
|
|
|
|
## the same shape with "target_expr" (the expression naming the variable) and
|
|
|
|
|
|
## target "@[expr]"; {} when `s` isn't one.
|
|
|
|
|
|
static func _parse_indirect(s: String) -> Dictionary:
|
|
|
|
|
|
var at := -1
|
|
|
|
|
|
var is_reset := false
|
|
|
|
|
|
if s.begins_with("@["):
|
|
|
|
|
|
at = 1
|
|
|
|
|
|
elif s.to_lower().begins_with("reset") and s.substr(5).strip_edges().begins_with("@["):
|
|
|
|
|
|
is_reset = true
|
|
|
|
|
|
at = s.find("@[") + 1
|
|
|
|
|
|
if at < 0:
|
|
|
|
|
|
return {}
|
|
|
|
|
|
var close := Expr.bracket_end(s, at)
|
|
|
|
|
|
if close < 0:
|
|
|
|
|
|
return {"src": s, "error": "@[ is missing its closing ]"}
|
|
|
|
|
|
var inner := s.substr(at + 1, close - at - 1).strip_edges()
|
|
|
|
|
|
if inner == "":
|
|
|
|
|
|
return {"src": s, "error": "Write an expression inside @[ ], e.g. @[option]"}
|
|
|
|
|
|
var target := s.substr(at - 1, close - at + 2)
|
|
|
|
|
|
var rest := s.substr(close + 1).strip_edges()
|
|
|
|
|
|
if is_reset:
|
|
|
|
|
|
if rest != "":
|
|
|
|
|
|
return {"src": s, "error": "Write reset @[expr]"}
|
|
|
|
|
|
return {"src": s, "op": "reset", "target": target, "target_expr": inner, "expr": ""}
|
|
|
|
|
|
for op: String in ["+=", "-=", "*=", "/=", "="]:
|
|
|
|
|
|
if rest.begins_with(op) and not (op == "=" and rest.begins_with("==")):
|
|
|
|
|
|
var expr := rest.substr(op.length()).strip_edges()
|
|
|
|
|
|
if expr == "":
|
|
|
|
|
|
return {"src": s, "error": "Nothing after %s" % op}
|
|
|
|
|
|
return {"src": s, "op": op, "target": target, "target_expr": inner, "expr": expr}
|
|
|
|
|
|
return {"src": s, "error": "Not a statement; try @[name] = value"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## The real target of a statement: its "target", or for an indirect one
|
|
|
|
|
|
## "@name" from its expression. {"target", "error"}: the error is set when
|
|
|
|
|
|
## the expression fails or doesn't give a valid name.
|
|
|
|
|
|
static func resolve_target(st: Dictionary, ctx: RollContext) -> Dictionary:
|
|
|
|
|
|
if not st.has("target_expr"):
|
|
|
|
|
|
return {"target": st["target"], "error": ""}
|
|
|
|
|
|
var r := Expr.evaluate(str(st["target_expr"]), ctx)
|
|
|
|
|
|
if r["error"] != "":
|
|
|
|
|
|
return {"target": "", "error": str(r["error"])}
|
|
|
|
|
|
var nm := Expr.indirect_name(r["value"])
|
|
|
|
|
|
if nm["error"] != "":
|
|
|
|
|
|
return {"target": "", "error": str(nm["error"])}
|
|
|
|
|
|
return {"target": "@" + str(nm["name"]), "error": ""}
|
|
|
|
|
|
|
|
|
|
|
|
|
Logic cards engine: expressions, effects, choice/loop/variable/sheet cards, coroutine roller
- Expr: @vars, chain vars, dice tokens, dm/has/count, lone = as ==, errors as values, parse cache
- Effects: = += -= *= /= and reset (with prefix), number vs list semantics, logs, validation
- RollTable kinds and per-kind fields with factories; expression dice with end clamping
- TableEntry effects and expression pipe counts; JSON round trip through JsonIO
- TextExpander: {@prefix_*}, {= expr}, number display, expand_async and live render()
- Roller: coroutine with an explicit work stack, prompts for choice cards, loops,
10,000-action limit, partial tree on ctx.root, iterative flatten/collect_lit
- Variables keep numbers as numbers through StateStore
- Main: awaits the roll with a default (headless) prompt hook, iterative playback,
long chains show at once
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 13:38:42 -06:00
|
|
|
|
## Problems in effect text for the Build-mode editor: Array of {index (0-based
|
|
|
|
|
|
## statement number), src, error}. Empty when everything parses.
|
|
|
|
|
|
static func validate(text: String) -> Array[Dictionary]:
|
|
|
|
|
|
var out: Array[Dictionary] = []
|
|
|
|
|
|
var list := split(text)
|
|
|
|
|
|
for k in list.size():
|
|
|
|
|
|
var st := parse_statement(list[k])
|
|
|
|
|
|
var err := str(st.get("error", ""))
|
Dynamic pick options, show_if and indirect @[expr] names
Pick choice cards can take their options from variables (options_from:
@prefix_* or a @list, filtered by options_where with option, option_label
and option_value bound). A Chosen entry runs for whichever dynamic option
is picked; fixed entries stay as extras, listed first. Random weighs each
dynamic option as the Chosen entry and fixed ones by weight. Any pick
option can have show_if, which hides it from the pop-up and from Random;
with nothing offered the node stops with "No options available".
@[expr] reads or writes the variable named by expr in expressions,
effects (including reset) and text ({@[expr]}); bad computed names are
effect errors. JSON round trip, lint_options in lint_pipes, choice
pop-up value badges and previews, card and settings UI, docs, demo board
(Spend a find) and tests/test_options.gd.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 18:55:38 -06:00
|
|
|
|
if err == "" and st.has("target_expr"):
|
|
|
|
|
|
err = Expr.check(st["target_expr"])
|
Logic cards engine: expressions, effects, choice/loop/variable/sheet cards, coroutine roller
- Expr: @vars, chain vars, dice tokens, dm/has/count, lone = as ==, errors as values, parse cache
- Effects: = += -= *= /= and reset (with prefix), number vs list semantics, logs, validation
- RollTable kinds and per-kind fields with factories; expression dice with end clamping
- TableEntry effects and expression pipe counts; JSON round trip through JsonIO
- TextExpander: {@prefix_*}, {= expr}, number display, expand_async and live render()
- Roller: coroutine with an explicit work stack, prompts for choice cards, loops,
10,000-action limit, partial tree on ctx.root, iterative flatten/collect_lit
- Variables keep numbers as numbers through StateStore
- Main: awaits the roll with a default (headless) prompt hook, iterative playback,
long chains show at once
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 13:38:42 -06:00
|
|
|
|
if err == "" and st["op"] != "reset":
|
|
|
|
|
|
err = Expr.check(st["expr"])
|
|
|
|
|
|
if err != "":
|
|
|
|
|
|
out.append({"index": k, "src": list[k], "error": err})
|
|
|
|
|
|
return out
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## Runs every statement against the context. Returns the log, one line per
|
|
|
|
|
|
## statement: Array of {"text": String, "error": bool (only when true)}.
|
Plain Build engine: Describe, Builder, checks, inputs, collections, why trace
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>
2026-11-08 21:01:24 -06:00
|
|
|
|
## `source_id` is stored as the variables' source table. `facts`, when given,
|
|
|
|
|
|
## gets one why-trace fact per statement that changed something:
|
|
|
|
|
|
## {"type": "effect", "var": "@name" (or "@prefix_*" / a chain name), "op":
|
|
|
|
|
|
## "=" | "+=" | "-=" | "*=" | "/=" | "reset", "before": value or null,
|
|
|
|
|
|
## "after": value or null} ("count" instead of before/after for a prefix reset).
|
|
|
|
|
|
static func run(text: String, ctx: RollContext, source_id: String = "", facts: Variant = null) -> Array[Dictionary]:
|
Logic cards engine: expressions, effects, choice/loop/variable/sheet cards, coroutine roller
- Expr: @vars, chain vars, dice tokens, dm/has/count, lone = as ==, errors as values, parse cache
- Effects: = += -= *= /= and reset (with prefix), number vs list semantics, logs, validation
- RollTable kinds and per-kind fields with factories; expression dice with end clamping
- TableEntry effects and expression pipe counts; JSON round trip through JsonIO
- TextExpander: {@prefix_*}, {= expr}, number display, expand_async and live render()
- Roller: coroutine with an explicit work stack, prompts for choice cards, loops,
10,000-action limit, partial tree on ctx.root, iterative flatten/collect_lit
- Variables keep numbers as numbers through StateStore
- Main: awaits the roll with a default (headless) prompt hook, iterative playback,
long chains show at once
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 13:38:42 -06:00
|
|
|
|
var log: Array[Dictionary] = []
|
|
|
|
|
|
if text.strip_edges() == "":
|
|
|
|
|
|
return log
|
|
|
|
|
|
for src in split(text):
|
|
|
|
|
|
var st := parse_statement(src)
|
|
|
|
|
|
if st.has("error"):
|
|
|
|
|
|
log.append({"text": "%s: %s" % [src, st["error"]], "error": true})
|
|
|
|
|
|
continue
|
Dynamic pick options, show_if and indirect @[expr] names
Pick choice cards can take their options from variables (options_from:
@prefix_* or a @list, filtered by options_where with option, option_label
and option_value bound). A Chosen entry runs for whichever dynamic option
is picked; fixed entries stay as extras, listed first. Random weighs each
dynamic option as the Chosen entry and fixed ones by weight. Any pick
option can have show_if, which hides it from the pop-up and from Random;
with nothing offered the node stops with "No options available".
@[expr] reads or writes the variable named by expr in expressions,
effects (including reset) and text ({@[expr]}); bad computed names are
effect errors. JSON round trip, lint_options in lint_pipes, choice
pop-up value badges and previews, card and settings UI, docs, demo board
(Spend a find) and tests/test_options.gd.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 18:55:38 -06:00
|
|
|
|
if st.has("target_expr"):
|
|
|
|
|
|
var rt := resolve_target(st, ctx)
|
|
|
|
|
|
if rt["error"] != "":
|
|
|
|
|
|
log.append({"text": "%s: %s" % [src, rt["error"]], "error": true})
|
|
|
|
|
|
continue
|
|
|
|
|
|
st["target"] = rt["target"]
|
Logic cards engine: expressions, effects, choice/loop/variable/sheet cards, coroutine roller
- Expr: @vars, chain vars, dice tokens, dm/has/count, lone = as ==, errors as values, parse cache
- Effects: = += -= *= /= and reset (with prefix), number vs list semantics, logs, validation
- RollTable kinds and per-kind fields with factories; expression dice with end clamping
- TableEntry effects and expression pipe counts; JSON round trip through JsonIO
- TextExpander: {@prefix_*}, {= expr}, number display, expand_async and live render()
- Roller: coroutine with an explicit work stack, prompts for choice cards, loops,
10,000-action limit, partial tree on ctx.root, iterative flatten/collect_lit
- Variables keep numbers as numbers through StateStore
- Main: awaits the roll with a default (headless) prompt hook, iterative playback,
long chains show at once
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 13:38:42 -06:00
|
|
|
|
if st["op"] == "reset":
|
Plain Build engine: Describe, Builder, checks, inputs, collections, why trace
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>
2026-11-08 21:01:24 -06:00
|
|
|
|
log.append(_reset(st["target"], ctx, facts))
|
Logic cards engine: expressions, effects, choice/loop/variable/sheet cards, coroutine roller
- Expr: @vars, chain vars, dice tokens, dm/has/count, lone = as ==, errors as values, parse cache
- Effects: = += -= *= /= and reset (with prefix), number vs list semantics, logs, validation
- RollTable kinds and per-kind fields with factories; expression dice with end clamping
- TableEntry effects and expression pipe counts; JSON round trip through JsonIO
- TextExpander: {@prefix_*}, {= expr}, number display, expand_async and live render()
- Roller: coroutine with an explicit work stack, prompts for choice cards, loops,
10,000-action limit, partial tree on ctx.root, iterative flatten/collect_lit
- Variables keep numbers as numbers through StateStore
- Main: awaits the roll with a default (headless) prompt hook, iterative playback,
long chains show at once
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 13:38:42 -06:00
|
|
|
|
else:
|
Plain Build engine: Describe, Builder, checks, inputs, collections, why trace
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>
2026-11-08 21:01:24 -06:00
|
|
|
|
log.append(_assign(st, ctx, source_id, facts))
|
Logic cards engine: expressions, effects, choice/loop/variable/sheet cards, coroutine roller
- Expr: @vars, chain vars, dice tokens, dm/has/count, lone = as ==, errors as values, parse cache
- Effects: = += -= *= /= and reset (with prefix), number vs list semantics, logs, validation
- RollTable kinds and per-kind fields with factories; expression dice with end clamping
- TableEntry effects and expression pipe counts; JSON round trip through JsonIO
- TextExpander: {@prefix_*}, {= expr}, number display, expand_async and live render()
- Roller: coroutine with an explicit work stack, prompts for choice cards, loops,
10,000-action limit, partial tree on ctx.root, iterative flatten/collect_lit
- Variables keep numbers as numbers through StateStore
- Main: awaits the roll with a default (headless) prompt hook, iterative playback,
long chains show at once
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 13:38:42 -06:00
|
|
|
|
return log
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## Plain log lines (errors included), for copying and history.
|
|
|
|
|
|
static func log_text(log: Array) -> PackedStringArray:
|
|
|
|
|
|
var out := PackedStringArray()
|
|
|
|
|
|
for l: Variant in log:
|
|
|
|
|
|
out.append(str((l as Dictionary).get("text", "")) if l is Dictionary else str(l))
|
|
|
|
|
|
return out
|
|
|
|
|
|
|
|
|
|
|
|
|
Plain Build engine: Describe, Builder, checks, inputs, collections, why trace
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>
2026-11-08 21:01:24 -06:00
|
|
|
|
static func _assign(st: Dictionary, ctx: RollContext, source_id: String, facts: Variant = null) -> Dictionary:
|
Logic cards engine: expressions, effects, choice/loop/variable/sheet cards, coroutine roller
- Expr: @vars, chain vars, dice tokens, dm/has/count, lone = as ==, errors as values, parse cache
- Effects: = += -= *= /= and reset (with prefix), number vs list semantics, logs, validation
- RollTable kinds and per-kind fields with factories; expression dice with end clamping
- TableEntry effects and expression pipe counts; JSON round trip through JsonIO
- TextExpander: {@prefix_*}, {= expr}, number display, expand_async and live render()
- Roller: coroutine with an explicit work stack, prompts for choice cards, loops,
10,000-action limit, partial tree on ctx.root, iterative flatten/collect_lit
- Variables keep numbers as numbers through StateStore
- Main: awaits the roll with a default (headless) prompt hook, iterative playback,
long chains show at once
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 13:38:42 -06:00
|
|
|
|
var target: String = st["target"]
|
|
|
|
|
|
var op: String = st["op"]
|
|
|
|
|
|
var r := Expr.evaluate(st["expr"], ctx)
|
|
|
|
|
|
if r["error"] != "":
|
|
|
|
|
|
return {"text": "%s: %s" % [st["src"], r["error"]], "error": true}
|
|
|
|
|
|
var rhs: Variant = Expr.normalize(r["value"])
|
|
|
|
|
|
var label := ctx.display_name(target) if target.begins_with("@") else target
|
|
|
|
|
|
var cur: Variant = ctx.get_value(target)
|
|
|
|
|
|
var type := ""
|
|
|
|
|
|
if target.begins_with("@"):
|
|
|
|
|
|
var card := ctx.declared(target)
|
|
|
|
|
|
if card != null:
|
|
|
|
|
|
type = card.var_type
|
2026-11-10 21:12:47 -06:00
|
|
|
|
if type == RollTable.VAR_SCALE:
|
|
|
|
|
|
return _assign_scale(st, ctx, source_id, facts, rhs, cur, label)
|
Logic cards engine: expressions, effects, choice/loop/variable/sheet cards, coroutine roller
- Expr: @vars, chain vars, dice tokens, dm/has/count, lone = as ==, errors as values, parse cache
- Effects: = += -= *= /= and reset (with prefix), number vs list semantics, logs, validation
- RollTable kinds and per-kind fields with factories; expression dice with end clamping
- TableEntry effects and expression pipe counts; JSON round trip through JsonIO
- TextExpander: {@prefix_*}, {= expr}, number display, expand_async and live render()
- Roller: coroutine with an explicit work stack, prompts for choice cards, loops,
10,000-action limit, partial tree on ctx.root, iterative flatten/collect_lit
- Variables keep numbers as numbers through StateStore
- Main: awaits the roll with a default (headless) prompt hook, iterative playback,
long chains show at once
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 13:38:42 -06:00
|
|
|
|
var as_list := false
|
|
|
|
|
|
if op == "+=" or op == "-=":
|
|
|
|
|
|
if type == "text" or type == "list":
|
|
|
|
|
|
as_list = true
|
|
|
|
|
|
elif type == "number":
|
|
|
|
|
|
as_list = false
|
|
|
|
|
|
else:
|
|
|
|
|
|
as_list = not Expr.is_number(rhs) or (cur != null and not Expr.is_number(cur) and str(cur).strip_edges() != "")
|
|
|
|
|
|
var value: Variant
|
|
|
|
|
|
var line: String
|
|
|
|
|
|
match op:
|
|
|
|
|
|
"=":
|
|
|
|
|
|
if type == "number" and not Expr.is_number(rhs):
|
|
|
|
|
|
return {"text": "%s: %s is a number, not \"%s\"" % [st["src"], label, Expr.format_value(rhs)], "error": true}
|
|
|
|
|
|
value = Expr.to_value(rhs) if type == "number" else rhs
|
|
|
|
|
|
line = "%s = %s" % [label, _shown(value)]
|
|
|
|
|
|
"+=", "-=":
|
|
|
|
|
|
if as_list:
|
|
|
|
|
|
var item := Expr.format_value(rhs).strip_edges()
|
2026-11-14 13:40:20 -06:00
|
|
|
|
value = list_with(cur, item, op == "-=", ctx.declared(target) != null and ctx.declared(target).list_repeats)
|
Logic cards engine: expressions, effects, choice/loop/variable/sheet cards, coroutine roller
- Expr: @vars, chain vars, dice tokens, dm/has/count, lone = as ==, errors as values, parse cache
- Effects: = += -= *= /= and reset (with prefix), number vs list semantics, logs, validation
- RollTable kinds and per-kind fields with factories; expression dice with end clamping
- TableEntry effects and expression pipe counts; JSON round trip through JsonIO
- TextExpander: {@prefix_*}, {= expr}, number display, expand_async and live render()
- Roller: coroutine with an explicit work stack, prompts for choice cards, loops,
10,000-action limit, partial tree on ctx.root, iterative flatten/collect_lit
- Variables keep numbers as numbers through StateStore
- Main: awaits the roll with a default (headless) prompt hook, iterative playback,
long chains show at once
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 13:38:42 -06:00
|
|
|
|
line = "%s %s %s → %s" % [label, "+" if op == "+=" else "−", item, _shown(value)]
|
|
|
|
|
|
else:
|
|
|
|
|
|
var a: Variant = Expr.to_value(cur) if cur != null and str(cur).strip_edges() != "" else 0
|
|
|
|
|
|
var b: Variant = Expr.to_value(rhs)
|
|
|
|
|
|
if not Expr.is_number(a) or not Expr.is_number(b):
|
|
|
|
|
|
return {"text": "%s: %s needs a number" % [st["src"], label], "error": true}
|
|
|
|
|
|
var delta: Variant = b if op == "+=" else -b
|
|
|
|
|
|
value = Expr.normalize(a + delta)
|
|
|
|
|
|
line = "%s %s → %s" % [label, _signed(delta), _shown(value)]
|
|
|
|
|
|
"*=", "/=":
|
|
|
|
|
|
var a2: Variant = Expr.to_value(cur) if cur != null and str(cur).strip_edges() != "" else 0
|
|
|
|
|
|
var b2: Variant = Expr.to_value(rhs)
|
|
|
|
|
|
if not Expr.is_number(a2) or not Expr.is_number(b2):
|
|
|
|
|
|
return {"text": "%s: %s needs a number" % [st["src"], label], "error": true}
|
|
|
|
|
|
if op == "*=":
|
|
|
|
|
|
value = Expr.normalize(a2 * b2)
|
|
|
|
|
|
line = "%s ×%s → %s" % [label, Expr.format_value(b2), _shown(value)]
|
|
|
|
|
|
else:
|
|
|
|
|
|
if b2 == 0:
|
|
|
|
|
|
return {"text": "%s: can't divide by 0" % st["src"], "error": true}
|
|
|
|
|
|
value = floori(float(a2) / float(b2))
|
|
|
|
|
|
line = "%s ÷%s → %s" % [label, Expr.format_value(b2), _shown(value)]
|
|
|
|
|
|
ctx.save(target, value, source_id)
|
Plain Build engine: Describe, Builder, checks, inputs, collections, why trace
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>
2026-11-08 21:01:24 -06:00
|
|
|
|
if facts != null:
|
|
|
|
|
|
(facts as Array).append({"type": "effect", "var": target, "op": op, "before": cur, "after": ctx.get_value(target)})
|
Logic cards engine: expressions, effects, choice/loop/variable/sheet cards, coroutine roller
- Expr: @vars, chain vars, dice tokens, dm/has/count, lone = as ==, errors as values, parse cache
- Effects: = += -= *= /= and reset (with prefix), number vs list semantics, logs, validation
- RollTable kinds and per-kind fields with factories; expression dice with end clamping
- TableEntry effects and expression pipe counts; JSON round trip through JsonIO
- TextExpander: {@prefix_*}, {= expr}, number display, expand_async and live render()
- Roller: coroutine with an explicit work stack, prompts for choice cards, loops,
10,000-action limit, partial tree on ctx.root, iterative flatten/collect_lit
- Variables keep numbers as numbers through StateStore
- Main: awaits the roll with a default (headless) prompt hook, iterative playback,
long chains show at once
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 13:38:42 -06:00
|
|
|
|
return {"text": line}
|
|
|
|
|
|
|
|
|
|
|
|
|
2026-11-10 21:12:47 -06:00
|
|
|
|
## A scale value (Scales): "=" takes a step name or position, "+=" and "-="
|
|
|
|
|
|
## move it that many steps, stopping at the ends.
|
|
|
|
|
|
static func _assign_scale(st: Dictionary, ctx: RollContext, source_id: String, facts: Variant, rhs: Variant, cur: Variant, label: String) -> Dictionary:
|
|
|
|
|
|
var target: String = st["target"]
|
|
|
|
|
|
var op: String = st["op"]
|
|
|
|
|
|
var steps := ctx.scale_steps(target.trim_prefix("@"))
|
|
|
|
|
|
var value: Variant = rhs
|
|
|
|
|
|
var line := ""
|
|
|
|
|
|
if op == "+=" or op == "-=":
|
|
|
|
|
|
var b: Variant = Expr.to_value(rhs)
|
|
|
|
|
|
if not Expr.is_number(b):
|
|
|
|
|
|
return {"text": "%s: %s moves by a number of steps" % [st["src"], label], "error": true}
|
|
|
|
|
|
var delta := int(b) if op == "+=" else -int(b)
|
|
|
|
|
|
value = Scales.position_of(steps, cur) + delta if cur != null else delta
|
|
|
|
|
|
ctx.save(target, value, source_id)
|
|
|
|
|
|
line = "%s %s %s → %s" % [label, _signed(delta), "step" if absi(delta) == 1 else "steps", _shown(ctx.get_value(target))]
|
|
|
|
|
|
elif op == "=":
|
|
|
|
|
|
ctx.save(target, value, source_id)
|
|
|
|
|
|
line = "%s = %s" % [label, _shown(ctx.get_value(target))]
|
|
|
|
|
|
else:
|
|
|
|
|
|
return {"text": "%s: %s can only move up or down" % [st["src"], label], "error": true}
|
|
|
|
|
|
if facts != null:
|
|
|
|
|
|
(facts as Array).append({"type": "effect", "var": target, "op": op, "before": cur, "after": ctx.get_value(target)})
|
|
|
|
|
|
return {"text": line}
|
|
|
|
|
|
|
|
|
|
|
|
|
Plain Build engine: Describe, Builder, checks, inputs, collections, why trace
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>
2026-11-08 21:01:24 -06:00
|
|
|
|
static func _reset(target: String, ctx: RollContext, facts: Variant = null) -> Dictionary:
|
Logic cards engine: expressions, effects, choice/loop/variable/sheet cards, coroutine roller
- Expr: @vars, chain vars, dice tokens, dm/has/count, lone = as ==, errors as values, parse cache
- Effects: = += -= *= /= and reset (with prefix), number vs list semantics, logs, validation
- RollTable kinds and per-kind fields with factories; expression dice with end clamping
- TableEntry effects and expression pipe counts; JSON round trip through JsonIO
- TextExpander: {@prefix_*}, {= expr}, number display, expand_async and live render()
- Roller: coroutine with an explicit work stack, prompts for choice cards, loops,
10,000-action limit, partial tree on ctx.root, iterative flatten/collect_lit
- Variables keep numbers as numbers through StateStore
- Main: awaits the roll with a default (headless) prompt hook, iterative playback,
long chains show at once
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 13:38:42 -06:00
|
|
|
|
if target.ends_with("*"):
|
|
|
|
|
|
var prefix := target.trim_prefix("@").trim_suffix("*")
|
|
|
|
|
|
var names := {}
|
|
|
|
|
|
for n: String in ctx.persistent_vars:
|
|
|
|
|
|
if n.begins_with(prefix):
|
|
|
|
|
|
names[n] = true
|
|
|
|
|
|
for n in ctx.declared_names():
|
|
|
|
|
|
if n.begins_with(prefix):
|
|
|
|
|
|
names[n] = true
|
|
|
|
|
|
var errors := PackedStringArray()
|
|
|
|
|
|
for n: String in names:
|
|
|
|
|
|
var r := reset_one(n, ctx)
|
|
|
|
|
|
if r != "":
|
|
|
|
|
|
errors.append(r)
|
|
|
|
|
|
if not errors.is_empty():
|
|
|
|
|
|
return {"text": "reset %s: %s" % [target, "; ".join(errors)], "error": true}
|
Plain Build engine: Describe, Builder, checks, inputs, collections, why trace
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>
2026-11-08 21:01:24 -06:00
|
|
|
|
if facts != null:
|
|
|
|
|
|
(facts as Array).append({"type": "effect", "var": target, "op": "reset", "count": names.size()})
|
Logic cards engine: expressions, effects, choice/loop/variable/sheet cards, coroutine roller
- Expr: @vars, chain vars, dice tokens, dm/has/count, lone = as ==, errors as values, parse cache
- Effects: = += -= *= /= and reset (with prefix), number vs list semantics, logs, validation
- RollTable kinds and per-kind fields with factories; expression dice with end clamping
- TableEntry effects and expression pipe counts; JSON round trip through JsonIO
- TextExpander: {@prefix_*}, {= expr}, number display, expand_async and live render()
- Roller: coroutine with an explicit work stack, prompts for choice cards, loops,
10,000-action limit, partial tree on ctx.root, iterative flatten/collect_lit
- Variables keep numbers as numbers through StateStore
- Main: awaits the roll with a default (headless) prompt hook, iterative playback,
long chains show at once
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 13:38:42 -06:00
|
|
|
|
return {"text": "Reset %s (%d)" % [target, names.size()]}
|
|
|
|
|
|
var name := target.trim_prefix("@")
|
Plain Build engine: Describe, Builder, checks, inputs, collections, why trace
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>
2026-11-08 21:01:24 -06:00
|
|
|
|
var before: Variant = ctx.get_value("@" + name)
|
Logic cards engine: expressions, effects, choice/loop/variable/sheet cards, coroutine roller
- Expr: @vars, chain vars, dice tokens, dm/has/count, lone = as ==, errors as values, parse cache
- Effects: = += -= *= /= and reset (with prefix), number vs list semantics, logs, validation
- RollTable kinds and per-kind fields with factories; expression dice with end clamping
- TableEntry effects and expression pipe counts; JSON round trip through JsonIO
- TextExpander: {@prefix_*}, {= expr}, number display, expand_async and live render()
- Roller: coroutine with an explicit work stack, prompts for choice cards, loops,
10,000-action limit, partial tree on ctx.root, iterative flatten/collect_lit
- Variables keep numbers as numbers through StateStore
- Main: awaits the roll with a default (headless) prompt hook, iterative playback,
long chains show at once
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 13:38:42 -06:00
|
|
|
|
var err := reset_one(name, ctx)
|
|
|
|
|
|
if err != "":
|
|
|
|
|
|
return {"text": "reset %s: %s" % [target, err], "error": true}
|
|
|
|
|
|
var v: Variant = ctx.get_value("@" + name)
|
Plain Build engine: Describe, Builder, checks, inputs, collections, why trace
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>
2026-11-08 21:01:24 -06:00
|
|
|
|
if facts != null:
|
|
|
|
|
|
(facts as Array).append({"type": "effect", "var": "@" + name, "op": "reset", "before": before, "after": v})
|
Logic cards engine: expressions, effects, choice/loop/variable/sheet cards, coroutine roller
- Expr: @vars, chain vars, dice tokens, dm/has/count, lone = as ==, errors as values, parse cache
- Effects: = += -= *= /= and reset (with prefix), number vs list semantics, logs, validation
- RollTable kinds and per-kind fields with factories; expression dice with end clamping
- TableEntry effects and expression pipe counts; JSON round trip through JsonIO
- TextExpander: {@prefix_*}, {= expr}, number display, expand_async and live render()
- Roller: coroutine with an explicit work stack, prompts for choice cards, loops,
10,000-action limit, partial tree on ctx.root, iterative flatten/collect_lit
- Variables keep numbers as numbers through StateStore
- Main: awaits the roll with a default (headless) prompt hook, iterative playback,
long chains show at once
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 13:38:42 -06:00
|
|
|
|
if v == null:
|
|
|
|
|
|
return {"text": "Reset %s (cleared)" % ctx.display_name(name)}
|
|
|
|
|
|
return {"text": "Reset %s → %s" % [ctx.display_name(name), _shown(v)]}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## Resets one board variable (no "@"): a declared one goes back to its starting
|
|
|
|
|
|
## value, an undeclared one is deleted. Returns an error message or "".
|
|
|
|
|
|
static func reset_one(name: String, ctx: RollContext) -> String:
|
|
|
|
|
|
var card := ctx.declared(name)
|
|
|
|
|
|
if card == null:
|
2026-11-14 13:36:03 -06:00
|
|
|
|
var ledger_entry := LedgerMembers.find(ctx.board, name)
|
|
|
|
|
|
if not ledger_entry.is_empty():
|
|
|
|
|
|
ctx.save("@" + name, ledger_entry["start"], (ledger_entry["card"] as RollTable).id)
|
|
|
|
|
|
else:
|
|
|
|
|
|
ctx.erase("@" + name)
|
Logic cards engine: expressions, effects, choice/loop/variable/sheet cards, coroutine roller
- Expr: @vars, chain vars, dice tokens, dm/has/count, lone = as ==, errors as values, parse cache
- Effects: = += -= *= /= and reset (with prefix), number vs list semantics, logs, validation
- RollTable kinds and per-kind fields with factories; expression dice with end clamping
- TableEntry effects and expression pipe counts; JSON round trip through JsonIO
- TextExpander: {@prefix_*}, {= expr}, number display, expand_async and live render()
- Roller: coroutine with an explicit work stack, prompts for choice cards, loops,
10,000-action limit, partial tree on ctx.root, iterative flatten/collect_lit
- Variables keep numbers as numbers through StateStore
- Main: awaits the roll with a default (headless) prompt hook, iterative playback,
long chains show at once
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 13:38:42 -06:00
|
|
|
|
return ""
|
|
|
|
|
|
var r := card.initial_value(ctx)
|
|
|
|
|
|
ctx.save("@" + name, r["value"], card.id)
|
|
|
|
|
|
return str(r["error"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static func _shown(v: Variant) -> String:
|
|
|
|
|
|
var s := Expr.format_value(v)
|
|
|
|
|
|
return s if s != "" else "(none)"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static func _signed(v: Variant) -> String:
|
|
|
|
|
|
var s := Expr.format_value(v)
|
|
|
|
|
|
return s if s.begins_with("-") else "+" + s
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static func _compile() -> void:
|
|
|
|
|
|
if _stmt_re == null:
|
|
|
|
|
|
_stmt_re = RegEx.create_from_string("^(@?[A-Za-z_][A-Za-z0-9_]*)\\s*(\\+=|-=|\\*=|/=|=)(?!=)\\s*(.*)$")
|
|
|
|
|
|
_reset_re = RegEx.create_from_string("^(?i:reset)\\s+@([A-Za-z_][A-Za-z0-9_]*|)(\\*?)\\s*$")
|