VariableStorage

class VariableStorage

Properties

variables : Map<String, dynamic>
lengthint
isEmptybool
isNotEmptybool

Methods

getBooleanValue(String name)bool
getNumericValue(String name)num
getStringValue(String name)String
hasVariable(String name)bool
getVariable(String name)dynamic
getVariableAsExpression(String name)Expression
getVariableType(String name)ExpressionType
setVariable(String name, dynamic value)
clear({bool clearNodeVisits = false})

Clear all variables. By default node visit counts will not be cleared. To remove node visit counts as well, set clearNodeVisits to true.

Note that node visit variable names are prefixed with an @ symbol. If you have custom variables that start with an @ symbol these will also be retained if clearNodeVisits is false. These will need to be removed individually using remove.

remove(String name)

Remove a variable by name.

Accessing variable storage

Variable storage is accessed via the YarnProject.

final variables = yarnProject.variables;

Removing variables

In most cases variables should be retained for the life of the YarnProject. However there may be situations where variables need to be removed from storage. For example, in a game with many scenes, variables specific to that scene could be removed if they are no longer required.

Remove all variables with clear. By default this will retain node visit counts, which are also stored as variables. Node visit counts are used by Yarn for logic such as ‘do this if the node has already been visited’, so it’s best to leave these alone. However, to remove them as well set clearNodeVisits to true.

/// Clear all variables except node visit counts.
yarnProject.variables.clear();

/// Clear all variables including node visit counts.
yarnProject.variables.clear(clearNodeVisits: true);

Use remove to remove a single variable.

yarnProject.variables.remove('money');