Variables and scripting macros give you direct control over story state. Use them to store data, clean up values no longer needed, protect loop variables from async closures, evaluate side-effectful expressions, and drop into raw JavaScript when TwineScript isn’t enough.Documentation 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.
<<set expression>>
Evaluates the given expression and assigns the result to one or more story $variables or temporary _variables. The entire argument is treated as a single expression, so you can chain multiple assignments separated by commas.
- TwineScript (to operator)
- JavaScript operators
- Multiple assignments
A valid TwineScript or JavaScript expression. Supports the TwineScript
to assignment operator as well as all standard JavaScript assignment operators (=, +=, -=, *=, etc.).<<unset variableList>>
Removes story $variables, temporary _variables, and/or properties of objects stored within either. Accepts a comma-separated list.
A comma-separated list of story
$variables, temporary _variables, or property accessors on variables stored in either ($obj.prop, $arr[0], etc.).<<capture variableList>> … <</capture>>
Creates localized copies of the listed variables for use inside the macro body. This is only necessary when you need to capture a variable’s current value for use inside an asynchronous macro—such as <<link>>, <<button>>, <<repeat>>, or <<timed>>—because those macros execute their content at a later time, after the variable may have changed.
A comma-separated list of story
$variables and/or temporary _variables to localize.<<capture>> is only needed when a variable’s value will change between the time the async macro is invoked and when it actually runs—most commonly inside loops. For straightforward one-off uses of <<link>> or <<button>>, it is usually not required.<<run expression>>
Functionally identical to <<set>>. Intended to be mnemonically clearer for cases where the expression is arbitrary code rather than a variable assignment—use <<run>> to run code and <<set>> to set variables.
<<script [language]>> … <</script>>
Silently executes a block of JavaScript (default) or TwineScript code. A predefined output variable—a reference to a local content buffer—is available inside the block; anything appended to it will be inserted into the passage output after the block finishes.
- JavaScript (default)
- TwineScript
- Output buffer
Optional. The language to evaluate the block as. Case-insensitive. Accepts
JavaScript (default) or TwineScript. Added in v2.37.0.