Skip to content

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 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 throws away any state changes made since the last commit.

discardState(): void
Example
discardState();

resetState resets every plugin’s state to its starting values, and empties the reader’s history.

resetState(): void

Each plugin’s state goes back to whatever it passed to defineInitialState.

Example
resetState();

processLabel runs any onLabel callbacks that match a lexia.

processLabel<T extends BlockLexia>(lexia: T): Promise<undefined | T | boolean>
Example
processLabel(lexia);

evaluateExpression evaluates an expression from the screenplay.

evaluateExpression(expression: Expression): any
Example
dialogueLexia.expressions.forEach((expression) => {
console.log(evaluateExpression(expression));
});