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?
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-...
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
| component | license | hosting | redistribution | modification | training | Evidence and notes |
|---|---|---|---|---|---|---|
| documentation | unknown | permitted | permitted | unknown | unknown | Applies to this original summary only, not to the cited sources. |