Knots
Learn how knots and labels work in Pixi’VN, how to run them from ink scripts or JavaScript, and the differences between native ink and Pixi’VN integration.
As explained in the official documentation, the story is comprised of multiple linked sections which we call knots in ink terminology. The start of a knot is indicated in ink using at least two equals signs on the left hand side of the knot's name, and optionally on the right too.
=== london ===No, they are the same thing. In Pixi’VN, when you create a knot with ink, a label will be created internally and saved in the registry.
Run a knot
To run a knot you can use the following methods:
You can execute a knot using the Divert operator, which is represented by the -> start syntax. It corresponds to the jump functionality in the Pixi’VN library.
-> afterFor example:
=== start ===
Start
-> after
=== after ===
After
End
-> DONEYou can execute a knot using the Tunnels operator, which is represented by the -> start -> syntax. It corresponds to the call functionality in the Pixi’VN library.
-> guard_dialogue ->Or, using the Threads syntax, write the <- symbol followed by the name of the knot:
<- guard_dialogueThreads
Unlike native ink, in ink + Pixi’VN integration "Threads" are not supported, so the <- symbol corresponds to calling a knot instead of being a "Thread" operator.
For simplicity, in ink + Pixi’VN integration, ->-> and -> DONE will correctly close the label, so they are equivalent.
For example:
VAR reputation = 0
-> start
=== start ===
You are in the square.
* [Talk to the guard]
-> guard_dialogue ->
You return to the square.
-> start
You don't see this line because you are sent back to the city before.
* {reputation >= 1} [Ask for a favor]
The guard helps you.
-> END
=== guard_dialogue ===
The guard looks at you.
* [Greet]
"Hello citizen."
~ reputation += 1
->->
* [Insult]
"Hey you!"
~ reputation -= 1
->->Other features
A particularly useful form of temporary variable is a parameter. Any knot or stitch can receive a value as a parameter, which is treated as a local temporary variable inside that knot:
=== start ===
* [Accuse Hastings]
-> accuse("Hastings")
* [Accuse Mrs Black]
-> accuse("Claudia")
* [Accuse myself]
-> accuse("myself")
=== accuse(who) ===
"I accuse {who}!" Poirot declared.
"Really?" Japp replied. "{who == "myself":You did it?|{who}?}"
"And why not?" Poirot shot back.Parameters are the correct way to pass a temporary value from one knot or stitch into another, because ordinary temp variables are not accessible outside the stitch where they were declared.
Temporary variables (including parameters) are safe to use in recursive knots:
-> add_one_to_one_hundred(0, 1)
=== add_one_to_one_hundred(total, x) ===
~ total = total + x
{ x == 100:
-> finished(total)
- else:
-> add_one_to_one_hundred(total, x + 1)
}
=== finished(total) ===
"The result is {total}!" you announce.
-> ENDKnot addresses can also be passed as parameters. Use -> to indicate that a parameter is a divert target:
=== sleeping_in_hut ===
You lie down and close your eyes.
-> generic_sleep(-> waking_in_the_hut)
=== generic_sleep(-> waking) ===
You sleep perchance to dream etc. etc.
-> waking
=== waking_in_the_hut ===
You get back to your feet, ready to continue your journey.By default, a divert to another knot is executed in the next step, so the diverted content is shown only after the flow continues:
=== start ===
It is, first and foremost...
-> add2
=== add2 ===
...a story about the twelve labors of Hercules.
-> DONEIf the divert is placed right after the text, with no line break in between, the diverted knot is executed in the same step as the preceding text, so both are shown together:
=== start ===
It is, first and foremost...-> add2
=== add2 ===
...a story about the twelve labors of Hercules.
-> DONE