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!

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more →

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more