Skip to main content

Top level state

Top level state is accessible everywhere inside of a template. State is public by default which means that when a template is used, public state can be extruded. When using the :private visibility modifier state fields cannot be extruded.

template StatefulExample : CompanionType {

state float value; // define template-local state field

state float valueWithDefault = 100f;

state:private string privateState = "Not visible outside of this template";

// top level state can also be mapped to a companion field
state string itemName from $companion; // if no field/property name is provided, it assumes you want the 'itemName' field/property from the companion
state string itemRarity from $companion.rarity; // if a field/property name is provided, that will be used

// you can both map a companion field and provide a default value like this:
state int itemValue from $companion = 100;