TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/pompom454/tea/llms.txt
Use this file to discover all available pages before exploring further.
State object is the authoritative record of everything that has happened in a Tea story. It manages the full history of moments (both past and future within a session), the currently active moment, variables attached to moments, temporary variables, persistent story metadata, and an optional seedable pseudo-random number generator (PRNG).
History in Tea is divided into three conceptual layers: the full in-play history (past + future), the past in-play subset (past only), and the extended past (expired + past). Individual members below note which layer they operate on.
Getters
State.active
The active (present) moment object, with
title and variables properties.State.passage and State.variables shortcuts, or the passage() and variables() story functions.
State.bottom
The least recent moment within the full in-play history (past + future).
State.current
The current moment from the full history — the pre-play version of the active moment.
State.length
The number of moments in the past in-play history (past only).
State.passage
The title of the passage associated with the active (present) moment.
State.size
The number of moments within the full in-play history (past + future).
State.temporary
The current temporary variables (
_-sigiled variables in TwineScript).State.top
The most recent moment from the full in-play history (past + future).
State.turns
Total count of played moments in the extended past (expired + past).
State.variables
The story variables (
$-sigiled) from the active (present) moment.Methods
State.getVar(varName)
The current value of the named variable, or
undefined if it does not exist.The variable name including its sigil:
$ for story variables, _ for temporary variables. Example: "$charName".State.has(passageTitle)
true if any past moment has the given title; false otherwise.State.hasPlayed() or the hasVisited() story function instead.
The passage title to search for in the past in-play history.
State.hasPlayed(passageTitle)
true if the title appears in the extended past (expired + past); false otherwise.The passage title to search for in the extended past history.
State.index(index)
The moment at the given index from the bottom of the past in-play history.
An integer index.
0 is the least recent moment in the past history.State.isEmpty()
true if the full in-play history contains no moments.State.peek([offset])
The moment at the given offset from the top of the past in-play history.
0 (the most recent moment).
Optional non-negative integer offset from the top.
0 returns the most recent past moment.State.random()
A pseudo-random floating-point number in
[0, 1).0 (inclusive) and 1 (exclusive). When the seedable PRNG has been enabled via State.prng.init(), returns deterministic results from the seeded PRNG. Otherwise delegates to Math.random().
State.setVar(varName, value)
true if the variable was set successfully; false otherwise.The variable name including its sigil (
$ or _). Example: "$charName".The value to assign to the variable.
State.metadata
The State.metadata store provides a small key/value persistence mechanism that survives story restarts and browser restarts (private browsing modes may interfere). Use it for achievements, new game+ data, and playthough statistics — not as a replacement for saves.
State.metadata.size
The number of key/value pairs currently in the metadata store.
State.metadata.clear()
Removes all key/value pairs from the metadata store.
State.metadata.delete(key)
Removes the specified key and its associated value from the store.
The key to remove.
State.metadata.entries()
An array of
[key, value] pairs for every entry in the store.State.metadata.get(key)
The value associated with the key, or
undefined if absent.The key whose value should be retrieved.
State.metadata.has(key)
true if the key exists in the store.The key to test.
State.metadata.keys()
An array of all keys currently in the store.
State.metadata.set(key, value)
Sets a key/value pair in the metadata store. The value must be JSON-serializable. To update a value, simply set the key again.
The key to set.
A JSON-serializable value to associate with the key.
State.prng
The State.prng sub-object controls an optional seedable pseudo-random number generator that integrates into story state and saves for reproducible randomness.
State.prng.init([seed [, useEntropy]])
Initializes the seedable PRNG and integrates it into the story state and saves. Once called, State.random(), random(), and randomFloat() return deterministic results from the seed.
Optional explicit seed string. Strongly recommended to omit and allow automatic seeding.
When
true, pads an explicit seed with additional entropy to avoid identical playthroughs for all players.State.prng.isEnabled()
true if the seedable PRNG has been initialized.State.prng.pull
The current pull count (number of random values drawn), or
NaN if the PRNG is not enabled.State.prng.seed
The seed string used to initialize the PRNG, or
null if the PRNG is not enabled.