Advanced
These functions are the building blocks Inkweaver uses to process screenplay content. Most scripts and plugins never need them. They’re useful when you’re decorating commands that change how Inkweaver handles the screenplay.
commitState
Section titled “commitState”commitState saves the current state as a new step in the reader’s history.
commitState(): Promise<void>Inkweaver commits state for you as the story moves. Call this only if you’re writing a command that changes state and needs those changes saved as their own step.
If the step can’t be saved, the changes stay uncommitted, and the next commitState tries again.
Example
await commitState();discardState
Section titled “discardState”discardState throws away any state changes made since the last commit.
discardState(): voidExample
discardState();resetState
Section titled “resetState”resetState resets every plugin’s state to its starting values, and empties the reader’s history.
resetState(): voidEach plugin’s state goes back to whatever it passed to defineInitialState.
Example
resetState();processLabel
Section titled “processLabel”processLabel runs any onLabel callbacks that match a lexia.
processLabel<T extends BlockLexia>(lexia: T): Promise<undefined | T | boolean>Example
processLabel(lexia);evaluateExpression
Section titled “evaluateExpression”evaluateExpression evaluates an expression from the screenplay.
evaluateExpression(expression: Expression): anyExample
dialogueLexia.expressions.forEach((expression) => { console.log(evaluateExpression(expression));});