Ink provides LIST construction to manage complex states. You can implement three distinct patterns:
1. Flags
Treat each list entry as an event that has occurred.
- Use
+= to mark an event as having occurred. - Test presence using
? (is this entry in the list?) or !? (is this entry NOT in the list?).
2. State Machines
Treat each list entry as a sequential state.
- Use
= to set the state. - Use
++ to step forward to the next state or -- to step backward. - Test using
== (equality) or > (is the current state after this one?).
3. Properties
Treat the list as a set of possible values for a property. To change a property, remove the old state and add the new one.
- Use
-= to remove a state. - Use
+= to add a state. - Use
LIST_ALL(ListName) to clear all possible values from a variable assigned to a list.
// Flags Example
LIST GameEvents = foundSword, openedCasket, metGorgon
{ GameEvents ? openedCasket }
{ GameEvents ? (foundSword, metGorgon) }
~ GameEvents += metGorgon
// State Machine Example
LIST PancakeState = ingredients_gathered, batter_mix, pan_hot, pancakes_tossed, ready_to_eat
{ PancakeState == batter_mix }
{ PancakeState < ready_to_eat }
~ PancakeState++
// Properties Example
LIST OnOffState = on, off
LIST ChargeState = uncharged, charging, charged
VAR PhoneState = (off, uncharged)
* {PhoneState !? uncharged } [Plug in phone]
~ PhoneState -= LIST_ALL(ChargeState)
~ PhoneState += charging
You plug the phone into charge.
* { PhoneState ? (on, charged) } [ Call my mother ]