From 2bf181a68d6cdcfb71a1027939678e05c444bc7c Mon Sep 17 00:00:00 2001 From: David Masad Date: Thu, 28 Jan 2021 21:18:32 -0500 Subject: [PATCH] Testing interruptions and adding passage --- Tutorial.md | 32 ++++++++++++++++++++++++++++++++ at_the_party.html | 25 +++++++++++++++++++++---- examples/at_the_party.tw | 20 ++++++++++++++++++++ storymanager.js | 4 ++-- 4 files changed, 75 insertions(+), 6 deletions(-) diff --git a/Tutorial.md b/Tutorial.md index 43b85a2..488a2f0 100644 --- a/Tutorial.md +++ b/Tutorial.md @@ -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. \ No newline at end of file diff --git a/at_the_party.html b/at_the_party.html index 5179fda..b720ea4 100644 --- a/at_the_party.html +++ b/at_the_party.html @@ -141,8 +141,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) { @@ -193,7 +193,23 @@ StoryManager.storylets["Conversation"] = { } return storylets; } -};<<widget ShowStoryletLinks>> +}; + +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 + }] + } + } +}<<widget ShowStoryletLinks>> <<for _storylet range $args[0]>> <<capture _storylet>> [[_storylet.description|_storylet.passage][$currentStorylet=_storylet]]<br> @@ -203,7 +219,8 @@ StoryManager.storylets["Conversation"] = { <<set _possibleStories = window.SM.getStorylets(3)>> <<ShowStoryletLinks _possibleStories>><<set $talkingTo = $currentStorylet.character>> You make polite conversation with $talkingTo.name. <br> -[[Keep circulating | Start]] +[[Keep circulating | Start]]$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]].