DEV Community

Sunder Iyer
Sunder Iyer

Posted on

TIL Ink Variable Text

2021-03-24

Further exploring Ink and Fungus, I discovered they both support dynamic text via Variable Text and Text Variation systems, respectively.

The syntax is nearly identical.
In Ink

I entered a phase of {denial|anger|bargaining|depression|acceptance}.
Enter fullscreen mode Exit fullscreen mode

In Fungus

I entered a phase of [denial|anger|bargaining|depression|acceptance].
Enter fullscreen mode Exit fullscreen mode

What happens here is all possible variations are captured between braces/brackets and separated by the pipe characters into elements. When the text is revisited, we move to the next element until we reach the final one which is always displayed. This is the default behavior for both.
Alternate behaviors are supported.

  • Cycles (prefixed by &) allow looping of the elements as ordered
  • Once-only (prefixed by !) where elements are displayed once and the final element is empty i.e. blank
  • Shuffles (prefixed by ~) randomly picks an element

Demonstration in Ink

Today is {&Sun|Mon|Tue|Wed|Thu|Fri|Sat}.
I checked the calendar. {!It's payday!|It's the day after payday.}
The sky is {~bright|cloudy}.
Enter fullscreen mode Exit fullscreen mode

From the above, a week of random weather can be simulated and payday only happens once ever. What a sad tale!

Oldest comments (0)