Skip to main content

YarnRunner

Description:

  The YarnRunner record is used for loading and executing Yarn narrative scripts.

YarnRunner.ResultType

Type: Enumeration.

Description:

  Enum for types of results that can be returned.

Signature:

enum ResultType

-- Represents textual results.
"Text"

-- Represents choices or options.
"Option"

-- Represents errors.
"Error"

-- Only for special test use.
"Command"
end

state

Type: Readonly Field.

Description:

  Field for accessing Yarn script runtime variables.

Signature:

const state: {string: string | number | boolean}

__call

Type: Metamethod.

Description:

  The metamethod to create a Yarn script runner.

Signature:

metamethod __call: function(
self: YarnRunner,
filename: string,
startTitle: string,
state?: {string: string | number | boolean}, --[[{}]]
command?: {string: function}, --[[{}]]
testing?: boolean --[[false]]
): YarnRunner

Parameters:

ParameterTypeDescription
filenamestringThe name of the Yarn file to load and execute.
startTitlestringThe starting node/title in the Yarn script.
statetable[optional] Table for providing predefined variables.
command{string: function}[optional] Table of commands to execute.
testingboolean[optional] Boolean flag for testing mode. When in testing mode, the testing variables from Web IDE will be loaded. Defaults to false.

Returns:

Return TypeDescription
YarnRunnerReturns the YarnRunner object.

advance

Type: Function.

Description:

  Method to advance the narrative.

Signature:

advance: function(self: YarnRunner, choice?: integer): nil | ResultType, string | table

Parameters:

ParameterTypeDescription
choiceinteger[optional] Index of the choice if presented with options.

Returns:

Return TypeDescription
nil | ResultTypeReturns nil if the narrative ended. Returns enum string result when YarnRunner is still running.
string | tableDepending on the narrative, it can return a type of result and the associated content:
"Text" and a TextResult.
"Option" and an OptionResult.
"Error" and a string error message.
nil and a string indecating the narrative ends.