Audience: Beginner (no HTML/CSS/JS experience needed)

What this shows

How to pick a random line of text from a list each time a passage is shown, using the Underscore.js library that Snowman already includes.

How it works

Using this in your own story

  1. Make a list of possible strings: window.setup.myLines = ["A", "B", "C"];
  2. Show a random one with <%= _.sample(window.setup.myLines) %>.
  3. Combine with _.random(min, max) if you want random numbers instead (see the dicerolling example in the main cookbook).

Full source

:: StoryData
{
	"ifid":"66B5222B-5ED9-4148-8672-E793A6F90A61"
}

:: StoryTitle
Random Flavor Text in Snowman

:: UserScript[script]
window.setup = window.setup || {};
window.setup.flavorTexts = [
	"The wind howls through the trees.",
	"A distant bell tolls somewhere in the village.",
	"You hear footsteps behind you, but no one is there."
];

:: Start
<%= _.sample(window.setup.flavorTexts) %>

[[Listen again->Start]]

Download the .twee file


← Previous: Simple Image Gallery · All examples · Next: Yes or No Quiz with Scoring →