Pardon our dust! Docs for Yarn Spinner for Unity 3.2 and Yarn Spinner for Godot C# are on docs.yarnspinner.dev (the old docs site). Docs for Yarn Spinner for Unity 3.3 (pre-release, out ASAP), Yarn Spinner for Godot GDScript and Yarn Spinner for Unreal Engine (work in progress) are on /docs/ (the new docs site).

Dialogue

Co-ordinates the execution of Yarn programs.
public class Dialogue : ISmartVariableEvaluator, IDialogueResponder

Inherits from System.Object

Implements Yarn.ISmartVariableEvaluator, Yarn.IDialogueResponder

This type is basically a wrapper around the Yarn.VirtualMachine and provides a nicer interface into manipulating the vm from the perspective of dialogue instead of a stack machine.

#Constructors

#Dialogue(IVariableStorage)

Creates a new AsyncDialogue
public Dialogue(IVariableStorage variableStorage)

Parameters

Exceptions

  • System.ArgumentNullException
    If the variable storage is null there is no way to create an a dialogue object

#Fields

#NoOptionSelected

The value to indicate to the dialogue runner that no option was selected and dialogue should fall through to the rest of the program.
public const int NoOptionSelected = -1;

Type Int32

#Properties

#ContentSaliencyStrategy

What saliency content strategy does the dialogue use to select salient content?
public Saliency.IContentSaliencyStrategy ContentSaliencyStrategy { get; set; }

Type IContentSaliencyStrategy

#CurrentNode

Returns the current node, or null if one hasn't been set
public string? CurrentNode { get; }

Type String

#IsActive

Is true when dialogue is currently running, false otherwise.
public bool IsActive { get }

Type Boolean

#LogDebugMessage

The logger for debug messages, is forwarded to the VM
public Logger? LogDebugMessage { get; set; }

Type Logger

#LogErrorMessage

The logger for error messages, is forwarded to the VM
public Logger? LogErrorMessage { get; set; }

Type Logger

#NodeNames

Returns the names of all nodes in the program.
public IEnumerable<string> NodeNames { get; }

Type IEnumerable

Exists so that you don't have to go digging inside the protobuf yourself.

#Program

The compiled Yarn program used by the dialogue.
public Program? Program { get; set; }

Type Program

#Responder

The Responder for this dialogue, this is how the dialogue informs the rest of the system of important events
public IDialogueResponder? Responder { get; set; }

Type IDialogueResponder

#VariableStorage

The variable storage used by the dialogue
public IVariableStorage VariableStorage { get; set; }

Type IVariableStorage

#Methods

#CanCallFunction(string)

Asks the responder if it can handle the function by this name.
public bool CanCallFunction(string functionName)

Parameters

  • functionNamestring
    the name of the function

Returns Boolean: true if the responder can handle the function

For the in-built functions the VM will still ask it's responder if it would like to handle them instead allowing for engine specific overrides.

#GetHeaders(string)

Returns all headers on the requested node.
public IEnumerable<KeyValuePair<string, string>> GetHeaders(string nodeName)

Parameters

  • nodeNamestring
    The node whos headers you covet

Returns IEnumerable: The collection of headers as key-value pairs

Exceptions

  • System.InvalidOperationException
    Throws if there is no program set
This exists primarily so that you don't have to dig directly into the compiled protobuf types.

#GetHeaderValue(string, string)

Returns a single value from a single node's header.
public string? GetHeaderValue(string nodeName, string headerName)

Parameters

  • nodeNamestring
    The node whos header you covet
  • headerNamestring
    The header upon the requested node

Returns String: The value of the requested header on the requested node, or null if either the node or header doesn't exist

Exceptions

  • System.InvalidOperationException
    Throws if there is no program set
If you are requesting multiple headers it would be better to use GetHeaders(string) and filter that collection.

#GetNodeVisitCount(string)

Works out how many times the node has been visited.
public float GetNodeVisitCount(string nodeName)

Parameters

  • nodeNamestring
    the node whos visitation count you are cirous about

Returns Single: 0 if the node has never been visited, otherwise the number of times the node has been visited

See also

#GetSaliencyOptionsForNodeGroup(string)

Returns the list of salient options inside a node groups
public IEnumerable<Saliency.ContentSaliencyOption> GetSaliencyOptionsForNodeGroup(string nodeGroup)

Parameters

  • nodeGroupstring
    The node group you want the salient content from

Returns IEnumerable: Collection of salient content inside the node group, may be a single item if the requested nodegroup is just a single node

Exceptions

  • System.ArgumentException
    If the requested nodegroup isn't a node

#HandleCommand(Command, CancellationToken)

Requests the responder handle the current command and inform the VM when it is done so.
public ValueTask HandleCommand(Command command, CancellationToken token)

Parameters

  • The command encountered
  • tokenSystem.Threading.CancellationToken
    The cancellation token for this task

Returns ValueTask

#HandleDialogueComplete()

Informs the responder that dialogue is finishing
public ValueTask HandleDialogueComplete()

Returns ValueTask

#HandleLine(Line, CancellationToken)

Requests the responder handle the current line and inform the VM when it is done so.
public ValueTask HandleLine(Line line, CancellationToken token)

Parameters

  • The line encountered
  • tokenSystem.Threading.CancellationToken
    The cancellation token for this task

Returns ValueTask

#HandleNodeComplete(string, CancellationToken)

Informs the responder that a node has been exited and the VM will await it's processing of this.
public ValueTask HandleNodeComplete(string node, CancellationToken token)

Parameters

  • nodestring
    The name of the node exited
  • tokenSystem.Threading.CancellationToken
    The cancellation token for this task

Returns ValueTask

#HandleNodeStart(string, CancellationToken)

Informs the responder that a node has been entered and the VM will await it's processing of this.
public ValueTask HandleNodeStart(string node, CancellationToken token)

Parameters

  • nodestring
    The name of the node entered
  • tokenSystem.Threading.CancellationToken
    The cancellation token for this task

Returns ValueTask

#HandleOptions(OptionSet, CancellationToken)

Requests the responder handle the current option group and tell the VM which option was selected. If NoOptionSelected is returned the option group will be skipped over.
public ValueTask<int> HandleOptions(OptionSet options, CancellationToken token)

Parameters

  • The collection of options for the responder to use in it's selection
  • tokenSystem.Threading.CancellationToken
    The cancellation token for this task

Returns ValueTask: The id of the selected option

#HasAnyContent(string)

Determines if the requested node group has any content to show.
public bool HasAnyContent(string nodeGroup)

Parameters

  • nodeGroupstring
    The node group to check for content

Returns Boolean: True if there is content to show, false otherwise

This may return false for any number of reasons including:

#InvokeFunction(string, IConvertible[], CancellationToken)

Asks the responder to run the function, and provides the parameters from the stack and awaits it's completion.
public ValueTask<IConvertible> InvokeFunction(string functionName, IConvertible[] parameters, CancellationToken token)

Parameters

  • functionNamestring
    the name of the function
  • parametersSystem.IConvertible[]
    The collection of parameters for this function, the order is the order they were on the stack
  • tokenSystem.Threading.CancellationToken
    The cancellation token for this task

Returns ValueTask: The result of the function

#IsNodeGroup(string)

Works out if the node is part of a node group or not. If the node isn't a valid node will always return false.
public bool IsNodeGroup(string nodeName)

Parameters

  • nodeNamestring
    The node whos node groupedipidty you are curious about

Returns Boolean: true if the requested node is part of a node group

Exceptions

  • System.InvalidOperationException
    Throws if there is no program set

#IsNodeVisited(string)

Works out if the node has been visited.
public bool IsNodeVisited(string nodeName)

Parameters

  • nodeNamestring
    The node whos visitation you are curious about

Returns Boolean: True if the node has been visited at least once

See also

#NodeExists(string)

Determins if the requested node exists in the dialogue
public bool NodeExists(string nodeName)

Parameters

  • nodeNamestring
    the node whos existence you are curious about

Returns Boolean: True if the node exists, false otherwise

#PrepareForLines(List<string>, CancellationToken)

Informs the responder that the following lines are likely soon to be encountered and it should perform any preparation for their presentation.
public ValueTask PrepareForLines(List<string> lineIDs, CancellationToken token)

Parameters

  • lineIDsSystem.Collections.Generic.List<string>
    The collection of line ids
  • tokenSystem.Threading.CancellationToken
    The cancellation token for this task

Returns ValueTask

#SetNode(string, CancellationToken)

Sets the current node
public async ValueTask SetNode(string node, CancellationToken cancellationToken = default)

Parameters

  • nodestring
    the requested node
  • cancellationTokenSystem.Threading.CancellationToken
    A token that can be used to cancel the set node operation

Returns ValueTask

#Start(CancellationToken)

Starts dialogue at the value of CurrentNode.
public async ValueTask Start(CancellationToken cancellationToken = default)

Parameters

  • cancellationTokenSystem.Threading.CancellationToken

Returns ValueTask

Exceptions

  • System.InvalidOperationException
    If there is no node currently set as the entry point this method throws

See also

#StartDialogue(string, CancellationToken)

Starts dialogue from a specific entry node and will run until completion of dialogue.
public async ValueTask StartDialogue(string node, CancellationToken cancellationToken = default)

Parameters

  • nodestring
    The node to use as the entry point for the dialogue
  • cancellationTokenSystem.Threading.CancellationToken
    An optional external cancellation source for the dialogue operation.

Returns ValueTask

#Stop()

Requests the current dialogue stop
public async ValueTask Stop()

Returns ValueTask

This cancels the various tokens that are provided to all tasks so dialogue cancellation will percolate outwards from this point

#TryGetSmartVariable<T>(string, T)

Attempts to retrieve the requested smart variable's current value
public bool TryGetSmartVariable<T>(string name, out T result)

Type Parameters

  • T
    The type of the smart varible, must match the type of the variable itself or be convertible to that type

Parameters

  • namestring
    The name of the smart variable
  • resultT
    the smart variable itself

Returns Boolean: True if it was possible to retrieve the smart variable

#UnloadAll()

Wipes the current program
public void UnloadAll()

Generated from Yarn Spinner for Unity 3.3.