CharacterStorage

class CharacterStorage

The CharacterStorage is a cache for all Characters defined in your yarn scripts. This container is populated from the <<character>> commands as the YarnProject parses the input scripts.

Properties

isEmptybool
isNotEmptybool

Methods

contains(String name)bool

Returns true if a character with the given name or alias was defined.

operator[](String name)Character?

Retrieves the character with the given name/alias, or returns null if such character was not present.

clear()

Clear all characters from storage.

This could be used between scenes in preparation for loading a new set of characters. It would not generally be used while a dialog is in progress.

remove(String name)

Remove a character by name. Its aliases will also be removed.

This could be used if you are certain a character is no longer required. It would not generally be used while a dialog is in progress.

Accessing character storage

Character storage is accessed via the YarnProject.

final characters = yarnProject.characters;

Removing characters

There may be situations where characters need to be removed from storage. For example, in a game with many scenes, characters could be removed after a scene and new characters loaded for the next scene.

Remove all characters with clear.

yarnProject.characters.clear();

Use remove to remove a single character. Pass in the name of the character or any of its aliases. The character and all its aliases will be removed.

yarnProject.characters.remove('Jenny');