Knots
Pixi’VN における knot と label の仕組み、ink スクリプトや JavaScript からの実行方法、ink 本来の仕様と Pixi’VN との連携の違いを学びます。
公式ドキュメントで説明されているように、ストーリーは相互にリンクされた複数のセクションで構成され、ink の用語ではこれらを knots と呼びます。 ink では、knot の名前の左側に等号を少なくとも 2 つ記述すると、その knot の開始を示せます。右側にも等号を記述できますが、省略可能です。
=== london ===いいえ、同じものです。 Pixi’VN では、ink で knot を作成すると、内部的に label が作成され、レジストリに保存されます。
knot を実行する
knot を実行するには、次の方法があります:
Divert 演算子を使うと、-> start という構文で knot を実行できます。これは Pixi’VN ライブラリの jump 機能に相当します。
-> after例:
=== start ===
Start
-> after
=== after ===
After
End
-> DONETunnels 演算子を使うと、-> start -> という構文で knot を実行できます。これは Pixi’VN ライブラリの call 機能に相当します。
-> guard_dialogue ->また、Threads 構文では、\<- 記号の後に knot の名前を記述します:
<- guard_dialogueThreads
本来の ink とは異なり、ink + Pixi’VN 連携では「Threads」がサポートされていません。そのため、\<- 記号は「Thread」演算子ではなく、knot の呼び出しに相当します。
簡潔にするため、ink + Pixi’VN 連携では ->-> と -> DONE のどちらでも label を正しく終了でき、同じ意味になります。
例:
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
->->その他の機能
一時変数の中でも特に便利なのが、パラメーターです。どの knot や stitch も値をパラメーターとして受け取れます。受け取った値は、その 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.ある knot や stitch から別の knot や stitch に一時的な値を渡すには、パラメーターを使用するのが適切です。通常の temp 変数は、宣言された stitch の外からアクセスできないためです。
一時変数(パラメーターを含む)は、再帰的な knot でも安全に使用できます:
-> 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 のアドレスもパラメーターとして渡せます。 -> を使って、パラメーターがジャンプ先であることを示します:
=== 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.デフォルトでは、別の knot へのジャンプは次の step で実行されるため、ジャンプ先の内容は処理が再開されてから表示されます:
=== start ===
It is, first and foremost...
-> add2
=== add2 ===
...a story about the twelve labors of Hercules.
-> DONEテキストの直後に改行を挟まずにジャンプを記述すると、ジャンプ先の knot が直前のテキストと同じ step で実行され、両方がまとめて表示されます:
=== start ===
It is, first and foremost...-> add2
=== add2 ===
...a story about the twelve labors of Hercules.
-> DONE