How to Add Choices and Branching Paths in Twine – 5 Smart Ways to Use Links (For Choices and More!)
header01
How to Add Choices and Branching Paths in Twine – 5 Smart Ways to Use Links (For Choices and More!)

Intro

In this article, I will explain how to add choices and branching paths in Twine. Make sure you read the article about using simple links for branching and how to use variables in Twine and you can sign up here for more free Twine resources. You also can just buy my Twine essentials (quick start guide, cheat sheet, interactive tutorial and 3 graphical themes) for only 1 EUR!

One single feature is enough to create an interactive fiction and it's branching. Whether it's an immediate choice like you go left or right, or it could be based on some variables, it's the single most important feature of any interactive story. Twine uses links for choices but they can be used for so much more. Read further to see how!

How to use links?

Basic Link

The simple most important feature of Twine and any interactive fiction in general. Links are basically references to other passages and representing the player's choice. If you read my previous article, you already know the most basic syntax for a link:

This will literally show this text as a clickable link. When the player clicks on this text, it will transfer us to the passage called "Go to the next room". It works, but it can break the immersion or just looks off to represent it like this. What if you describe a room and just want to investigate and click on things in the text. And we are not even speaking about debugging a game where all passages have names like "Go", "Proceed", "Next"... surely you will be confused and start having headaches due to the name collisions.

Link with displayname

You can separate the passage name and the actual text shown to the players. In the first two examples below, "Go to the next room" will be shown on the screen but the actual passage name where we redirect to is "room_2". The third example shows the same link syntax but the link is part of the actual sentence.

So, why is using a separate displayname a good thing? Because as your story grows in length and complexity, it will be difficult to manage so many passages and branches but this way, you can have a system (naming convention) and you don't have to worry about how it would look on the screen since the displayed and the actual texts are two different things.

Link in a variable

Let's say there is a side quest or adventure in your story and you can depart at multiple points. So you can save the name of the "left from" passage into a variable:

(set: $town to "Frosthill")

...and later on, you can use the variable in a link like this:

[[Go back to town->$town]]

Link reveals content

You can use a link not to redirect to another passage but show new content, in the example below, if the player clicks on "Investigate the footprints", it will be replaced by the content after that without the square brackets:

The section inside the square brackets is a "hook", a piece of content. It's special because there is a modifier in front of it, a macro (it could be some formatting too but here it's a link macro). So, when the user clicks on the link "Investigate the footprints", the link will be replaced by the content inside. It can be more than just some text.

In the example below, clicking on the link will reveal some text and another link to the "ask-companion" passage.

If you don't want the original text to disappear, just use link-repeat instead of link.

Link changing variables

Imagine a scene where the player is in the shop and can buy things, you just need a link like this:

We have a hook attached to the repeatable (link-repeat:) because (link:) would disappear after 1 click, and the hook contains the logic to change variables: decrease money and increment the number of potions. But what if the player is out of gold? Shall we give some feedback if the purchase was successful or not? How to make sure the text won't generate a lot of empty lines? Here is the improved sample code with variable initialization (I will explain below):

Probably by now you understand why you must understand the Harlowe syntax for games using anything more than simple links and just using the toolbar will not be enough.

First we set the gold and potions variables (in a real life scenario, it would be set way before that shop scene). The curly brackets ( { and } ) will remove whitespaces (newlines, spaces etc.) and reduce all to one space.

Then we use link-rerun now, it will rewrite its content, not just repeat its logic and append text, this makes more sense here so we won't write to the screen 10 lines about purchasing a potion, just one.

If player has enough gold, we do the same as we did before and show a notification text with current gold and potions.

If the player ran out of gold, we reveal a named hook called "noGoldMessage". The (hidden:) macro will hide it first, we use this special syntax to define it (|name>) and its content is a text message in red and the values of gold and number of potions.

This will look like this:

Game screen showing potion purchase and gold count, using link-rerun and a named hook.

And when we have not enough gold:

Insufficient gold to buy potions in game.

Conclusion

Links are far more then just a way to change passages and I hope the article gave you an idea about what they can do. Stay tuned for more tips and tricks!

Help

Need more tips and tricks for FREE?

Sign up to my Twine newsletter for more:

Do you need a boost?

I have resources, graphical templates, tutorials etc. for Twine starting from 1 EUR, these bundles can save you hours and hours and will give your good-looking templates so your game looks professional.

Need help? Let's talk!

I can give you a head start if you want by offering my time and help you personally. Use the button below to book a call with me and you can ask me your questions in advance.

One thought on “How to Add Choices and Branching Paths in Twine – 5 Smart Ways to Use Links (For Choices and More!)

Leave a Reply

Your email address will not be published. Required fields are marked *