Testing interruptions and adding passage

This commit is contained in:
David Masad
2021-01-28 21:18:32 -05:00
parent 37c5740060
commit 2bf181a68d
4 changed files with 75 additions and 6 deletions

View File

@@ -152,3 +152,35 @@ To compile this with Tweego, run:
Is it even a real party if you aren't buttonholed by another guest at some point or another? In many games you'll want to allow some storylets to override the other options and require the player to engage with them now. We do this via a storylet that has the `interrupt==true` property.
(**Note:** At the moment, if there is more than one interrupting storylet only the first one is fired, regardless of priority or anything else. TODO: Incorporate some sort of interrupt ranking, queue etc.)
Let's have a 20% chance of another random guest coming up and talking to the player. We add this storylet to the StoryManager:
```javascript
StoryManager.storylets["Buttonholed"] = {
name: "Buttonholed",
tags: [],
generate: function() {
if (Math.random() < 0.2) {
let char = randomChoice(State.variables.characters);
return [{
passage: "Being approached",
description: "You see " + char.name + " approaching you.",
interrupt: true,
character: char
}]
}
}
}
```
You'll notice that this storylet leads to the same `Conversation` passage as the previous "Conversation" storylet. The only difference is that since this one has the `interrupt` property, the player will have no other option but to engage with them.
However, maybe we want to give the player a choice here: engage the buttonholer in conversation, or avoid it -- at the risk of snubbing them. To do that, we could create a new passage:
```
:: Being approached
$currentStorylet.character.name is coming toward you to talk. You can [[talk to them | Conversation]], or risk snubbing them by [[trying to get away | Start]].
```
We have to be sure to change the `passage` in the `"Buttonholed"` storylet to this new passage as well.

File diff suppressed because one or more lines are too long

View File

@@ -35,6 +35,22 @@ StoryManager.storylets["Conversation"] = {
}
};
StoryManager.storylets["Buttonholed"] = {
name: "Buttonholed",
tags: [],
generate: function() {
if (Math.random() < 0.2) {
let char = randomChoice(State.variables.characters);
return [{
passage: "Being approached",
description: "You see " + char.name + " approaching you.",
interrupt: true,
character: char
}]
}
}
}
:: Start
You stand at the edge of the grand ballroom in the Duchess's palace.<br>
<<set _possibleStories = window.SM.getStorylets(3)>>
@@ -45,3 +61,7 @@ You stand at the edge of the grand ballroom in the Duchess's palace.<br>
<<set $talkingTo = $currentStorylet.character>>
You make polite conversation with $talkingTo.name. <br>
[[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]].

View File

@@ -38,8 +38,8 @@ StoryManager.getStorylets = function(n=null, tag=null, respect_interrupt=true)
// Check for interruptions
// TODO: Handle more than one interruption
if (respect_interrupt)
for (let storylet in allStorylets)
if (storylet.interrupt) return [storylet];
for (let i in allStorylets)
if (allStorylets[i].interrupt) return [allStorylets[i]];
// Get n stories in priority order
if (n != null) {