Making new functions and calling knots
The Calling functions topic introduced functions for accepting input, possibly producing output, and explained how ink's built-in functions can be called.
It is also possible to create new functions in ink using the function
keyword. Any new functions created in ink can be used like any others, and they are often a useful way to create separate lines of code that can be used across a project or multiple times without the need to write the same code again.
In this topic, we will explore how to create new functions using the function
keyword. We will learn how they can be called, perform a small task, and even potentially return data. In Chapter 2, Knots, Diverts, and Looping Patterns, we discussed knots initially. Different sections of a story are defined by a name. In ink, functions, as we will learn, are special types of knots. This relationship means knots can also be called and passed data.
A function is created in ink using...