DEV Community

Sunder Iyer
Sunder Iyer

Posted on

3 3

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!

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay