Skip to content

1681-engine / index / DialogueRunner

Class: DialogueRunner ​

Defined in: src/dialogue/DialogueRunner.ts:38

Runs a DialogueScript: hands the game one step at a time — a line, a set of choices, the end — and moves on when the game says the line was read (next) or a choice made (choose). It draws nothing: the game's own box shows a ShownLine however it likes (a typewriter, a portrait from tags).

ts
const talk = new DialogueRunner(script, { vars: save.flags, onCommand: (name, args) => game.run(name, args) });
let step = talk.start();
// on a press: step = step.type === 'line' ? talk.next() : talk.choose(picked);

Constructors ​

Constructor ​

ts
new DialogueRunner(script, options?): DialogueRunner;

Defined in: src/dialogue/DialogueRunner.ts:47

Parameters ​

ParameterType
scriptDialogueScript
optionsDialogueOptions

Returns ​

DialogueRunner

Properties ​

script ​

ts
readonly script: DialogueScript;

Defined in: src/dialogue/DialogueRunner.ts:48


vars ​

ts
readonly vars: Record<string, unknown>;

Defined in: src/dialogue/DialogueRunner.ts:39

Accessors ​

at ​

Get Signature ​

ts
get at(): string | null;

Defined in: src/dialogue/DialogueRunner.ts:71

The node the dialogue is in, or null once it has ended.

Returns ​

string | null


current ​

Get Signature ​

ts
get current(): DialogueStep;

Defined in: src/dialogue/DialogueRunner.ts:66

The step showing now.

Returns ​

DialogueStep

Methods ​

choose() ​

ts
choose(index): DialogueStep;

Defined in: src/dialogue/DialogueRunner.ts:94

Picks a choice by its index (as shown). A locked or unknown index changes nothing.

Parameters ​

ParameterType
indexnumber

Returns ​

DialogueStep


evaluate() ​

ts
evaluate(source): ExprValue;

Defined in: src/dialogue/DialogueRunner.ts:117

The value of an expression over this dialogue's variables, for a game that shares the language.

Parameters ​

ParameterType
sourcestring

Returns ​

ExprValue


jump() ​

ts
jump(node): DialogueStep;

Defined in: src/dialogue/DialogueRunner.ts:107

Jumps to a node from outside (the game's own event broke in).

Parameters ​

ParameterType
nodestring

Returns ​

DialogueStep


next() ​

ts
next(): DialogueStep;

Defined in: src/dialogue/DialogueRunner.ts:87

The line showing was read: on to the next line, the choices, or wherever the node leads.

Returns ​

DialogueStep


restore() ​

ts
restore(save): DialogueStep;

Defined in: src/dialogue/DialogueRunner.ts:132

Puts a saved dialogue back where it was, without running the node's set and do again.

Parameters ​

ParameterType
saveDialogueSave

Returns ​

DialogueStep


save() ​

ts
save(): DialogueSave;

Defined in: src/dialogue/DialogueRunner.ts:121

Returns ​

DialogueSave


start() ​

ts
start(node?): DialogueStep;

Defined in: src/dialogue/DialogueRunner.ts:81

Begins at node (default the script's start, else its first node).

Parameters ​

ParameterType
nodestring | undefined

Returns ​

DialogueStep


stop() ​

ts
stop(): DialogueStep;

Defined in: src/dialogue/DialogueRunner.ts:112

Ends the dialogue now.

Returns ​

DialogueStep


visited() ​

ts
visited(node): number;

Defined in: src/dialogue/DialogueRunner.ts:76

How many times a node was entered.

Parameters ​

ParameterType
nodestring

Returns ​

number

Released under the MIT License.