Variable

From Castle Wiki
Revision as of 18:18, 11 May 2022 by Ben (talk | contribs)

A Variable stores a numeric value to be used at play time. Variables can be used for accumulating player scores in a game, tracking player money and transactions, remembering properties of objects in a simulation deck, or can just be used as conveniently editable parameters which you can tweak later.

Variables have a name, such as $score.

Variable types

Actor variables

The actor variables section of a blueprint

Local variables are variables that are accessible by only the actor that owns it and its values cant be edited by other actors

Global variables

The global variables tab of the Tools panel

Global variables are variables that are accessed by all actors in all cards in the deck. Global variables have 2 possible lifetimes, 'deck play' and 'persistent per player'.

Global variable lifetime

Deck play

Variables that have deck play lifetime have values that only last for one deck play before reseting to their initial value either by the player restarting the deck or leaving the deck and returning to it.

Persistent per player

Variables with 'persistent per player' lifetime save progress between deck plays. Leaving and returning to a deck with a persistent variable will preserve the value of the variable, as will restarting the deck.


Reading and writing variables at play time

You can read the value of a variable using an Expression. You can change the value of a variable in Rules using the Set variable response. You can also do things when variables change using triggers such as When a variable changes or When a variable reaches a value.

Displaying the value of variables

Inside any Text, you can write the variable name (including the $) to display the value of the variable when the deck is played. For example: "Your score is $score".