How to Write a Dialog or a Story using Ink

Published

I’ve been very impressed with Genshin Impact lately, a game developped using Unity that really impressed me by its narrative and performance while being free to play (It actually runs somewhat fine on my laptop despite only having a ryzen integrated graphics). In doing so, it proved that Unity was not only a solution for low budget indie developpers but also for million dollar game companies.

With all this gaming happening, I figured it was high time I went looking for something I could use to build a complete dialogue system in Unity, which brought me to discover Ink, by Inkle studios.

About Ink

Ink is a simple and yet full-featured scripting language that was developed to power games that were relying heavily on text such as 80 Days. It has evolved a bit since then and can now be used in order to create stories to be read on the web or (as is my usecase) in the Unity game engine.

In order to get started with Ink, you will want to download the Inky editor which comes with an integrated player, letting you easily play through your story as you write it and export it when finally ready.

An example dialogue written in Ink from the 80 Days game

Your first story

I believe there is no better to learn than by doing so we’ll get to writing a simple story to start with using a few simple pointers.

A line of text is as simple as it gets, which every line read all at once and separated from the next by a newline character.

This is a line of text!
This is another line of text!

You can write a section of the story inside a “knot” which can be named and lets you navigate your story by using a divot. Here’s how it looks like in action.

"My story starts here and it won't end before I show you how to use a knot!"
-> MY_KNOT

=== MY_KNOT===
This is my knot, there's only one like it and it's mine.
-> conclusion

== conclusion ==
And it's finally over.
-> END

We can introduce choices in our story using a simple list. Ink will go through the nested content behind the choice but won’t come out of it unless told to.

"How about you give me your number? It's not everyday I meet a famous author!"
    * "Sure here you go!"
        "Thanks, i'll give you a call someday"
    * [Play it cool. Like Driver] She's cute, better play it cool. "How about we get a coffee together first. Then I'll give you my number."
        "Sure, I was hoping you'd ask!" she says, laughing sheepishly.


There's a fork in the forest path in front of me.
Where should I go?
    * [Go Left]
        "I'm lost, maybe I should have gone right?"
    * [Go Right]       
        "I'm lost, maybe I should have gone left?"

You can use either ”*” or ”+” to represent a choice. There is ONE subtle difference: if you write a choice and then revisit it, choices that have been marked using ”*” and selected before won’t show again.

One last thing for our first look at Ink is the use of conditionals.

{ my_fork_name } "I'll only speak this line if you've been to my_fork_name.
{ not my_fork_name } "I'll only speak this line if you haven't been to my_fork_name.

Let’s put it all together:

There's a fork in the forest path in front of me.
-> FORK

== FORK ==
Where should I go?
    * [Go Left]
        "I'm lost, maybe I should have gone right?"
                -> LOST
    * [Go Right]       
        "I'm lost, maybe I should have gone left?"
                -> LOST
                
    * { LOST } [Go Home]
        -> HOME
        
== LOST ==
+ [Go back]
    -> FORK

== HOME ==
I was never meant for hiking, I'll go watch bird on TV.
-> END

Going through this story, you’ll get lost once to start with and then only will you have the choice to go back home, thanks to a conditional visit to the “LOST” knot that sends you back to the fork.

Try it out by copying and pasting it in your Inky editor!

The road ahead

We’ve successfully written a short interactive story to go through. There’s a lot more to learn in order to master Ink but that’s a nice start.

I plan on writing a following to this post to show how to use variables, using logic and custom functions to add randomness and turn a simple story into more of a true adventure game.

My feelings so far are that Ink is a pretty nicely thought out scripting language for writing dialogs and story. As I’ve said earlier, I’m currently working on a dialogue system for my Unity gamedev needs and hope to showcase it on this blog in the near future.

If you’ve enjoyed trying out Ink, please check out Inkle Studios’s twitter and let them know you enjoy their work!