Files
StoryletManager/examples/tutorial.tw
2021-02-20 21:11:19 -05:00

117 lines
3.2 KiB
Plaintext

:: StoryTitle
At the Duchess's Party
:: StoryData
{
"ifid": "BE18C022-A213-466C-8DD1-DCCD5CB1DF48"
}
:: Story JavaScript [script]
Config.passages.nobr = true; // Deal with linebreaks.
State.variables.reputation = 0;
State.variables.playerKnowledge = {poetry: 0, industry: 0, astronomy: 0};
State.variables.characters = [
{
name: "Arabella Armstrong",
poetry: 3, industry: 0, astronomy: 0
},
{
name: "Blake Brookhaven",
poetry: 0, industry: 3, astronomy: 0
},
{
name: "Claudio Croix",
poetry: 0, industry: 0, astronomy: 3
}
]
// Choose one of an array
var randomChoice = function(vals) {
return vals[Math.floor(Math.random() * vals.length)];
};
StoryManager.storylets["Conversation"] = {
name: "Conversation",
tags: ["circulating"],
generate: function*() {
for (let i in State.variables.characters) {
let character = State.variables.characters[i];
let storylet = {
passage: "Conversation",
description: "Talk to " + character.name,
priority: 1,
character: character
}
yield storylet
}
}
};
StoryManager.storylets["Buttonholed"] = {
name: "Buttonholed",
tags: ["circulating"],
generate: function*() {
if (Math.random() < 0.2) {
let char = randomChoice(State.variables.characters);
yield {
passage: "Being approached",
description: "You see " + char.name + " approaching you.",
interrupt: true,
character: char
};
}
}
};
StoryManager.storylets["Conversation topic"] = {
name: "Conversation topic",
tags: ["during conversation"],
generate: function*() {
for (let topic in State.variables.playerKnowledge) {
if (State.variables.playerKnowledge[topic] > 0 |
State.variables.talkingTo[topic] > 0)
yield {
passage: "Conversation topic",
description: "Talk about " + topic,
priority: 1,
topic: topic
};
}
}
};
:: Start
You stand at the edge of the grand ballroom in the Duchess's palace.<br>
<<getStoryletLinks 3 "circulating">>
:: Conversation
<<set $talkingTo = $currentStorylet.character>>
You talk with $talkingTo.name. <br>
<<getStoryletLinks 3 "during conversation">>
[[Keep circulating | Start]]
:: Being approached
$currentStorylet.character.name is coming toward you to talk. <br>
You can [[talk to them | Conversation]], or risk snubbing them by [[trying to get away | Start]].
:: Conversation topic
<<set $topic = $currentStorylet.topic>>
<<if $playerKnowledge[$topic] < $talkingTo[$topic] >>
<<set $playerKnowledge[$topic] = $playerKnowledge[$topic] + 1>>
(They tell you about $topic) (Knowledge of $topic goes up)
<<elseif $playerKnowledge[$topic] == $talkingTo[$topic]>>
(You discuss $topic) (reputation goes up slightly)
<<set $reputation = $reputation + 1>>
<<elseif $playerKnowledge[$topic] > $talkingTo[$topic]>>
(You tell them about $topic) (reputation goes up)
<<set $reputation = $reputation + 2>>
<</if>><br><br>
[[Keep circulating | Start]]