String Templates in Whimsy
String templates allow you to create dynamic text that change based on variables, or just randomly. This is especially useful for creating varied dialogue, tracking progress, or creating more immersive gameplay where actors don't repeat the same lines like robots.
Where you can use templates
String templates can be used in several blocks within scenario nodes:
- The "Say a line" block
- The "Show message" block
- The "Evaluate string" block
Template Syntax
Whimsy supports two main templating features:
1. Variable Substitution: ${variable}
You can insert the value of a variable using the ${variable name}
syntax:
Hello, my name is ${characterName}!
If the variable characterName
contains "Alice", the output will be Hello, my name is Alice!
2. Random Text Selection: {option1|option2|option3}
You can have Whimsy randomly select text from a list of options using the pipe character (|
) as a separator:
{Good day|Hello there|Greetings}, traveler!
Each time this text is displayed, Whimsy will randomly choose one of the greetings. For example, Greetings, traveler!
Combining Templates
You can combine both features in the same text:
{Hello|Hi|Greetings}, ${playerName}! You have ${flowerCount} flowers.
Possible output: Hello, ManlyBadassHero! You have 5 flowers.
Escaping Templates
If you want to display the template syntax as literal text, you can escape it with a backslash (\
) before the $
symbol and brackets:
To use variables, type \$\{variableName\}. To make random outputs, use \{this|that\}.
This will display: To use variables, type ${variableName}. To make random outputs, use {this|that}.
Using Templates in Scenario Blocks
In "Say a line" and "Show message" Blocks
When an actor needs to say something dynamic:
- Add a "Say a line" block to your scenario
- In the text field, enter your template:
I see you have ${flowerCount} flowers. {That's nice|Impressive|How lovely}!
If you need to make a displayed variable's content rainbow-colored or styled in some other way, make sure you apply the style to the whole templating marker, including $
, {
, and }
symbols.
In "Evaluate string" Block
The "Evaluate string" block processes a template and lets you store the result in a variable or use in other blocks. This is useful for:
- Generating random names or descriptions that are persistent
- Creating consistent responses that you'll use multiple times
- Pre-processing complex text before displaying it
In any block, if the resulting text still contains templating markers, the text will be templated again.
For example, you can have a variable positive adjective
of type string with content {cool|kind|friendly|heroic|stoic|...}
, and you can use it as He is known to be ${positive adjective}
, so it becomes, for example, He is known to be cool.
.
Examples
Varied NPC Greetings
{Good morning|Hello|Hi there}, traveler!
{Welcome to our village|It's a fine day, isn't it?|How can I help you today?}
Progress-Based Dialogue
You have ${flowerCount} out of 10 flowers.
{Keep looking!|You're getting there!|Almost done!}