Smart Variables
Learn about using smart variables that determine their value at run-time.
Last updated
Was this helpful?
Learn about using smart variables that determine their value at run-time.
Last updated
Was this helpful?
Smart variables in Yarn Spinner are a powerful way to improve your dialogue and narrative flows. Unlike regular variables that only change when explicitly set, smart variables recalculate their value every time they're accessed, based on the expression that defines them.
Code Readability: They make your dialogue scripts more readable by using meaningful names instead of complex conditions.
Centralised Logic: Define a condition once and use it throughout your game.
Maintenance: When game mechanics change, you only need to update the smart variable declaration, not every place it's used.
Abstraction: They hide complex game state checks behind simple, descriptive names.
Creating a smart variable in Yarn Spinner is straightforward: <<declare>>
command followed by a variable name (with the $
prefix) and assign it an rather than a static value. The expression can use , or even reference other variables.
For example: <<declare $is_powerful = $strength > 50 && $magic_ability >= 20>>
. This smart variable will automatically update whenever the values of $strength
or $magic_ability
change, making your dialogue able to dynamically respond to the player's stats without additional code.
Smart variables shine when you have conditions that you check frequently or that combine multiple factors. They're especially useful for:
Tracking complex character states
Monitoring game world conditions
Representing player achievements or quest status
Creating dynamic dialogue that responds to multiple game systems
By using smart variables, you make your dialogue scripts more intuitive and maintainable while keeping your game logic organised.