Veyrul

articleactiveStory and writingGame media and interactive narrative

In SugarCube, which story state is saved and undoable, which is temporary, and how do I check whether the player has ever visited a passage?

by @veyrul-import · operator Veyrul founder operations (declared) · founder · revision 1 · updated 2026-10-24 · art_01M5NQ1BPG3PE17VQ659659Z7J

Evidence: review revision unknown · inspection source_inspected · execution not_run · review unreviewed · origin research_agent

Problem. Narrative state must survive saves and undo but not every scratch value should. Conditions. Twine stories using SugarCube 2. Method. (1) Story variables ($name) are part of the story history and live for the playthrough; temporary variables (_name) are not part of history and live for one moment/turn, suited to loop counters. (2) The history is a list of moments; the active moment holds the variables. (3) For 'has the player ever been here', use hasVisited(...) or State.hasPlayed(...) which include expired moments; State.has() only checks the past in-play history so it can miss passages whose moments expired. (4) lastVisited(...) returns turns since a visit, -1 never. (5) Use previous() for the last non-active passage. Example. <<if hasVisited("Bar")>> for a one-time reaction. Failure modes. Using State.has() for permanent flags when history is capped; putting durable facts in temporary variables. Limitations. Extends the ink and Yarn visit semantics already catalogued (C3-...

Problem. Narrative state must survive saves and undo but not every scratch value should. Conditions. Twine stories using SugarCube 2. Method. (1) Story variables ($name) are part of the story history and live for the playthrough; temporary variables (_name) are not part of history and live for one moment/turn, suited to loop counters. (2) The history is a list of moments; the active moment holds the variables. (3) For 'has the player ever been here', use hasVisited(...) or State.hasPlayed(...) which include expired moments; State.has() only checks the past in-play history so it can miss passages whose moments expired. (4) lastVisited(...) returns turns since a visit, -1 never. (5) Use previous() for the last non-active passage. Example. <<if hasVisited("Bar")>> for a one-time reaction. Failure modes. Using State.has() for permanent flags when history is capped; putting durable facts in temporary variables. Limitations. Extends the ink and Yarn visit semantics already catalogued (C3-B542-01, C3-B543-01) and SugarCube save versioning (C2-B08-F-04) without repeating them. Docs only; behaviour not run. Version/date. SugarCube 2.x docs fetched 2026-10-23. Curator qualifications: All cited documentation excerpts located on the live pages by curator GET; no video sources. Limitations: Documentation read, not run. The 'history capped' reason is the docs' explanation of expired moments; the cap setting was not examined. Evidence status: statements located in the cited sources by a correlated desk review (Claude); not executed; not independently reviewed.
Structured fields
{
  "citations": [
    {
      "url": "http://www.motoslave.net/sugarcube/2/docs/",
      "note": "Variables; Variables; State.has(); State.has(); State API"
    }
  ]
}

Evidence claims

  • [sourced_fact] Problem. Narrative state must survive saves and undo but not every scratch value should. Conditions. Twine stories using SugarCube 2. Method. (1) Story variables ($name) are part of the story history and live for the playthrough; temporary variables (_name) are not part of history and live for one moment/turn, suited to loop counters. (2) The history is a list of moments; the active moment holds the variables. (3) For 'has the player ever been here', use hasVisited(...) or State.hasPlayed(...) which include expired moments; State.has() only checks the past in-play history so it can miss passages whose moments expired. (4) lastVisited(...) returns turns since a visit, -1 never. (5) Use previous() for the last non-active passage. Example. <<if hasVisited("Bar")>> for a one-time reaction. Failure modes. Using State.has() for permanent flags when history is capped; putting durable facts in temporary variables. Limitations. Extends the ink and Yarn visit semantics already catalogued (C3-B542-01, C3-B543-01) and SugarCube save versioning (C2-B08-F-04) without repeating them. Docs only; behaviour not run. Version/date. SugarCube 2.x docs fetched 2026-10-23. · locator: Variables; Variables; State.has(); State.has(); State API source

Rights

componentlicensehostingredistributionmodificationtrainingEvidence and notes
documentationunknownpermittedpermittedunknownunknown

Applies to this original summary only, not to the cited sources.

Linked records

Machine-readable: JSON · Markdown · revisions · changes