Learning Ink: Part 8: Knot Parameters and Functions



Learning Ink


Ink is a scripting language for creating interactive fiction like choose-you-own-adventures and other vast, branching stories.


Knot (and Stitch) Parameters

While knots and stitches can be thought of as “sections of code,” they can also act similar to functions in other programming languages. Parameters can be passed to knots and stitches and used as variables within their sections, allowing for a more modular approach to creating sections that can respond to the data passed to it.


When used in a loop structure, knots with parameters can serve to highlight the previous choices made.




While knots with parameters can work like functions and allow for reacting to data passed to them, Ink does have functions.

Functions are a special type of knot but use the keyword “function”. This also enables them to use additional functionality not available to regular knots and stitches: returning data using the “return” keyword.

Similar to many other scripting languages, functions in Ink can be called, perform some task, and then return the result of the task.


However, while functions enable the useful feature of being able to react and respond with a return value, they also have some limitations.

As covered in the documentation, functions:

  • cannot contain stitches
  • cannot use diverts or offer choices
  • can call other functions
  • can include printed content
  • can return a value of any type
  • can recurse safely



GitHub Gist Version:

CONST name = "Dan"
~ temp fretCount = 0
It was {dayOfWeek()}.
I was unsure about asking him out on a date.
-> Chapter_1
=== Chapter_1 ===
{&What should I do? | What if I didn't say anything? | Should I ask him out?}
+ [Did he even like guys?]
~ fretCount++
-> Chapter_1
* I should just do it!
I let it go for weeks.
{fretCount > 2: After thinking about it multiple times, I finally asked him out.}
{fretCount < 2: Finally, I asked him out. }
Why hadn't I thought about what I was going to wear?
Here I am, 30 minutes before the date and I haven't picked out my clothes!
* (Look_Good) [Pick out something good.] I took some time and picked out something good.
* (Random_Clothes) [Don't bother.] I just grabbed some clothes off the floor and ran out.
Finally, I was ready.
{Look_Good: "You look good, {name}!"}
{Random_Clothes: "Ready?"}
But I hadn't made dinner plans! And they we were, standing outside his apartment.
He turned to me. "What should we eat, {name}?"
-> Pizza_Choices("")
=== Pizza_Choices(previousChoice) ===
{previousChoice != "": (We've already talked about having {previousChoice}.) }
* [Pizza?] He shook his head. "I don't like pizza."
-> Pizza_Choices("pizza")
* [Salad?] "Not a salad."
-> Pizza_Choices("salad")
+ [Nothing?] {"We have to eat something!"|"Stop being silly, {name}!"}
-> Pizza_Choices("nothing")
* [Sushi?] "Sushi sounds good!"
We walked to the local sushi place.
-> END
=== function dayOfWeek() ===
~ return "{~Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday}"