Hack Your Own Adventure Story With Yarn Spinner

We are big fans of programmed texts for education. You know, the kind where you answer a question and go to a new page based on your answer. But they can also be entertaining “choose your own adventure” stories. You might say, “You are standing in front of an oak door, two meters high, with an iron handle. Do you a) open it? b) knock on it? c) ignore it?” Then, based on your answer, you go to a different part of the story. These are tough to write, but you can get some help using Yarn Spinner and the Yarn scripting language.

The original purpose of Yarn is to produce conversations for games. There’s a tutorial for that. The difference is to produce a book, you get a choose your own adventure PDF at the end. For the tutorial, you can try to read the text on the left-hand side of the editor or just press Test (at the top) and let it “read” the tutorial to you, which is a little more fluid.

The scripting language is mostly text, but you can have branching logic, which is critical for the book generation. You can also set variables as in:

<<set $gold to 5>>

Then you can test variables with <<if>> as you might expect. You can also jump to other parts of the script using <<jump>>. This works with nodes that look like this:

title: HackadayNode
---// Yarn script goes here===

That’s about it. We took the liberty of writing a cheeky Hackaday adventure. The source code is available, too. You’ll notice the script is simplistic. It doesn’t merge the lines, so if you have, say, three jumps to node X, you will get three copies of node X in the book. Then again, that helps your page count, and it doesn’t distract from the enjoyment of the finished product. And, yes, we added the title graphic after the fact.

It should be possible to write programmed instruction material with this, too. Why just pretend to submit a project to Hackaday when you could do it for real so easily?

8 thoughts on “Hack Your Own Adventure Story With Yarn Spinner

  1. Z machine games are quite similar I imagine? I liked playing them a few years back on my smartphone. Unlike visual games, text based games are great fun if you are not impatient or in a hurry and can spend an hour or so casually reading through the game and weighing choices. They are the natural evolution to people who like reading fiction or fantasy novels I feel.

    Also I think such games would be better written in a flowchart based game creator, since you can visually see the flow of the game.

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.