Hidden updates in Ink
Building interactive fiction in Ink sometimes feels like an exercise in smoke and mirrors; there are times where you want to script events where it feels like the reader has agency when actually their decision doesn't change the future story at all1, and there are times where you want the future story to be impacted by a decision but you don't want to reveal it immediately.
One example came up this week when I was asked how you could ask a series of questions without revealing whether each individual question was answered correctly - but changing what happens after depending on the overall number that were correct.
How could we do that?
To begin with, anytime we want to track a number or a score in Ink we want a variable.
VAR correct_answers = 0
Next, we're going to want to do the same thing after every correct answer: add one to the score, and then carry on the story from where we were. "Do the same thing in multiple places in the story" is what tunnels are for; knots/sections that use the special ->-> operator to return the story back to where ever you came from.
=== good_answer ~correct_answers = correct_answers + 1 // or you can use the special short hand // that means the same thing as above // ~correct_answers += 1 ->->
Finally, we want each question to provide two or more possible answers, but which ever one you pick the story will continue the same way - just maybe via a side trip to the good_answer knot. Multiple choices which all go the same place use a "gather" (which is just a - on its own line to mark the end of a block of choices).
By using a gather we can avoid having to make every question its own knot, diverting to it, and then having to divert on to the next question. Instead, we can have them all in a single place with a nice clear flow (and a lot less typing).
=== questions Is a wombat a wom, or a bat? * [Wom] * [Bat] * [What?] -> good_answer -> - Is the pineapple a pine, or an apple? * [I dispute the nature of your question] -> good_answer -> * [Pine] * [Apple] - You have answered {correct_answers} questions correctly. -> END
Putting it all together, our script would look something like this:
VAR correct_answers = 0 -> questions === good_answer ~correct_answers = correct_answers + 1 // or you can use the special short hand // that means the same thing as above // ~correct_answers += 1 ->-> === questions Is a wombat a wom, or a bat? * [Wom] * [Bat] * [What?] -> good_answer -> - Is the pineapple a pine, or an apple? * [I dispute the nature of your question] -> good_answer -> * [Pine] * [Apple] - You have answered {correct_answers} questions correctly. -> END
If you want to try it out, you can paste the whole lot into the 'demo' script editor at VisualInk and give it a run for yourself, experimenting with changes as they catch your fancy.
Discussion of this post is probably happening as replies to its announcement on the fediverse.
Footnotes:
Remember that the reader's experience in interactive fiction is the story that they see. So whether they answer the gate guard with an insult or flattery may not be something that you track or that impacts the plot - but it will have changed the experience of that reader and shaped how they feel about the rest of the story.