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).

YarnLibrary

Manages built-in and custom Yarn Spinner functions and commands. Command arguments are automatically coerced to match parameter types; Node-typed parameters are resolved from the scene tree.
class_name YarnLibrary
extends RefCounted

Inherits from RefCounted

#Nested Types

#Constants

#COMPILER_DECLARATIONS

Types of the built-in functions that the Yarn compiler doesn't already know about. The importer passes these to the compiler, so these functions can be used anywhere, including inside a line. Functions in the Yarn standard library, like dice() and round(), don't need to be listed. Keep this in step with _register_builtin_functions().
const COMPILER_DECLARATIONS = Array[Dictionary]([{"name": "visited", "parameters": [...], "returnType": "bool"}, {"name": "visited_count", "parameters": [...], "returnType": "number"}, {"name": "has_any_content", "parameters": [...], "returnType": "bool"}, {"name": "abs", "parameters": [...], "returnType": "number"}, {"name": "sign", "parameters": [...], "returnType": "number"}, {"name": "clamp", "parameters": [...], "returnType": "number"}, {"name": "lerp", "parameters": [...], "returnType": "number"}, {"name": "inverse_lerp", "parameters": [...], "returnType": "number"}, {"name": "smoothstep", "parameters": [...], "returnType": "number"}, {"name": "pow", "parameters": [...], "returnType": "number"}, {"name": "sqrt", "parameters": [...], "returnType": "number"}, {"name": "wrap", "parameters": [...], "returnType": "number"}, {"name": "mod", "parameters": [...], "returnType": "number"}, {"name": "plural", "parameters": [...], "returnType": "string", "variadicParameterType": "string"}, {"name": "ordinal", "parameters": [...], "returnType": "string", "variadicParameterType": "string"}, {"name": "length", "parameters": [...], "returnType": "number"}, {"name": "uppercase", "parameters": [...], "returnType": "string"}, {"name": "lowercase", "parameters": [...], "returnType": "string"}])

#FUNCTION_ERROR

Sentinel returned by call_function when the invoked function reported an error via report_function_error. A StringName is a distinct Variant type from String, so it can never collide with a legitimate function return value.
const FUNCTION_ERROR = &"__yarn_function_error__"

#Methods

#call_function(String, Array, YarnVirtualMachine)

func call_function(func_name: String, stack: Array, vm: YarnVirtualMachine) -> Variant

Parameters

Returns Variant

#cleanup_stale_targets()

func cleanup_stale_targets() -> void

#dispatch_command(String, Node)

Returns {status, handled, is_async, result, error}. This is a coroutine and MUST be awaited: coroutine command handlers run to completion inside it (so for `<<wait 2>>` the two seconds elapse before it returns). Handlers that return a Signal instead are reported via is_async/result for the caller to await.
func dispatch_command(command_text: String, dialogue_runner: Node) -> Dictionary

Parameters

  • command_textString
  • dialogue_runnerNode

Returns Dictionary

#find_command_target(String)

Resolve a node by name: registered targets, then unique name, then tree search.
func find_command_target(target_name: String) -> Node

Parameters

  • target_nameString

Returns Node

#get_function_param_count(String)

func get_function_param_count(func_name: String) -> int

Parameters

  • func_nameString

Returns int

#has_command(String)

func has_command(command_name: String) -> bool

Parameters

  • command_nameString

Returns bool

#has_function(String)

func has_function(func_name: String) -> bool

Parameters

  • func_nameString

Returns bool

#has_instance_command(String)

func has_instance_command(command_name: String) -> bool

Parameters

  • command_nameString

Returns bool

#is_function_error(Variant)

static func is_function_error(value: Variant) -> bool

Parameters

  • valueVariant

Returns bool

#parse_bool(String)

static func parse_bool(text: String) -> Dictionary

Parameters

  • textString

Returns Dictionary

#parse_int32(String)

static func parse_int32(text: String) -> Dictionary

Parameters

  • textString

Returns Dictionary

#parse_single(String)

static func parse_single(text: String) -> Dictionary

Parameters

  • textString

Returns Dictionary

#register_command_target(String, Node)

func register_command_target(target_name: String, target: Node) -> void

Parameters

  • target_nameString
  • targetNode

#register_command(String, Callable, PackedStringArray)

Registers a Yarn command. Declare typed parameters on the handler and the dispatcher converts each argument from the Yarn script to that type — func give(item: String, count: int, loud: bool) receives a real int and bool from <<give sword 3 true>>. Supported: String, int, float, bool, Vector2, Vector3, Color, and Node-derived classes (resolved by node name). A value that can't convert is a command error, not a silent default. Use a NAMED method for this — GDScript lambdas carry no parameter metadata, so lambda handlers receive raw strings.
func register_command(command_name: String, callable: Callable, param_names: PackedStringArray = []) -> void

Parameters

  • command_nameString
  • callableCallable
  • param_namesPackedStringArray

#register_function(String, Callable, int)

func register_function(func_name: String, callable: Callable, param_count: int = -1) -> void

Parameters

  • func_nameString
  • callableCallable
  • param_countint

#register_instance_command(String, Script, String)

Register a command bound to a specific class. The first argument in the yarn command is resolved to a node and type-checked against target_class.
func register_instance_command(command_name: String, target_class: Script, method_name: String = "") -> void

Parameters

  • command_nameString
  • target_classScript
  • method_nameString

#report_function_error(String)

Records that a built-in function received input it cannot handle. call_function returns FUNCTION_ERROR on the same call, which the virtual machine treats as a reason to stop the dialogue.
func report_function_error(message: String) -> void

Parameters

  • messageString

#set_program(YarnProgram)

func set_program(program: YarnProgram) -> void

Parameters

#set_target_root(Node)

func set_target_root(root: Node) -> void

Parameters

  • rootNode

#set_virtual_machine(YarnVirtualMachine)

func set_virtual_machine(vm: YarnVirtualMachine) -> void

Parameters

#set_vm_context(YarnSaliencyStrategy, YarnVariableStorage)

func set_vm_context(strategy: YarnSaliencyStrategy, storage: YarnVariableStorage) -> void

Parameters

#take_function_error()

Returns the pending function error message and clears it.
func take_function_error() -> String

Returns String

#unregister_command_target(String)

func unregister_command_target(target_name: String) -> void

Parameters

  • target_nameString

#unregister_command(String)

func unregister_command(command_name: String) -> void

Parameters

  • command_nameString

#unregister_function(String)

func unregister_function(func_name: String) -> void

Parameters

  • func_nameString

#unregister_instance_command(String)

func unregister_instance_command(command_name: String) -> void

Parameters

  • command_nameString

Generated from Yarn Spinner for Godot GDScript 3.3.