Branching dialogue; disappearing choices

Hello there,
I have found lots of topics about this regarding Sugarcube and Harlowe, but I have struggled to find anything directly regarding Chapbook. I’d like to ask if anyone knows how I would make certain choices disappear if they’re selected. I know that if I understood the language differences between Sugarcube, Harlowe, and Chapbook I could take pre-existing advice and just translate it. But I’m not quite that smart yet. So let me offer an example.
If I have a passage about having a pet snail, and I write the following:

[[pet snail]]
[[sing to snail]]
[[feed snail]]
[[watch the sun set a little longer]]

And the reader clicks “pet snail”, when they complete the action, I don’t want them to see that option pop up anymore. I would like it to appear like this:

[[sing to snail]]
[[feed snail]]
[[watch the sun set a little longer]]

Or replace the text with something like, “You already pet the snail,” if that would be easier.
I’m familiar (mostly) with if-then statements in Chapbook, but I have no idea how I would phrase it in this context. Maybe, [if petsnail===true then insert something here about opacity], but I am not sure what exact phrase to use.
Thank you for your patience, and I apologize if someone has already asked this question or if I have tagged this post incorrectly!
Thanks,
hazy

2 Likes

I am not real familiar with chapbook, but there’s a built in passage.visits variable that counts how many times a passage has been viewed.

I think you can say in the passage:


[if passage.visits === 1]
You feed your pet snail.
[else]
You've already fed your pet snail.

I’m not quite sure of the format for how’d you’d reference a different passage from another, but it may be:
[EDIT - corrected for my own education]

[if passage.visits('feedsnail') eq 0]
[[Feed the snail.->feedsnail]]
[else]
Your snail is happy and fed and taking a nap.
[continue]

Conditional display in Chapbook

Worst case scenario, you can set a variable like $fedsnail = false and set it to true once the snail is fed, then conditionally display either the text in the passage or the link to it based on that variable. [if $fedsnail eq true][…]

[if $fedsnail eq false]

2 Likes

Thank you so much for your reply!! I’ll give it a try and report back.

1 Like

Hanon has the right ideas here but let me add some clarification on syntax. I think the approach in general depends on how often you need to know if the player fed the snail.

If it’s something you’ll refer to often, I’d use a dedicated variable for it like fedSnail like Hanon suggests (on a side note, you don’t need to put $ in front of variables in Chapbook, though it’s allowed–this is something other formats require). To check it:

[if fedSnail]
[[Feed the snail.->feedsnail]]

[continue]
Anything here will always display.

I wrote the short form here since it’s a simple boolean variable, but you could also write [if fedSnail === true]. Chapbook doesn’t have an eq operator–I think Hanon was thinking of SugarCube.

If you only need to check this to make sure the player only clicks the link once, using passage.visits probably is better. (Hanon’s example code is right here.)

Chapbook doesn’t directly support looking up passage visits on another passage right now, but you can do this with a dash of JavaScript. Chapbook maintains a variable named trail that records each passage the player visits in an array. So you can use JavaScript’s includes method:

[if trail.includes('Some other passage name')]
You've visited "Some other passage name."

[else]
First time, eh?
3 Likes

Thank you @klembot! I’ve been promiscuously trying different systems and the syntaxes start to blur together!

4 Likes

I am so, so grateful. I’m gonna implement this here and report back! Thank you to everyone for doing their best to explain the technical details to me. You’ve both been fantastically helpful.

4 Likes