节点、线和选项
在 Yarn Spinner 中,您的所有对话都存储在 .yarn 文件。纱线文件只是纯文本文件,您可以在任何文本编辑器中对其进行编辑。
节点
纺纱机文件包含节点。节点是放置对话的地方。您可以在文件中链接多个节点。节点用于分离故事的各个部分,并使管理较长的故事和分支变得更容易。
每个节点至少有一个标头和主体的集合。所有节点都至少有一个标头,即标题。标题是节点的名称,正文包含包含游戏对话的 Yarn 脚本。
节点的标题很重要,因为您的游戏使用节点标题来告诉 Yarn Spinner 开始运行哪个节点。当您想跳转到另一个节点时,也可以使用节点的标题。
节点标题不会向玩家显示。
[!警告] 节点标题必须以字母开头,可以包含字母、数字和下划线。
因此 FirstNode、First_Node 和 Node1 有效,但 First Node 和 1stNode 无效。
[!危险] 节点名称不能包含
. (period).节点名称能够在 Yarn Spinner 1 中包含句点,并且如果您的 Yarn Spinner 1.yarn脚本的节点名称中有句点,您可以使用 升级脚本 将它们(以及所有相关的跳转和选项)转换为使用_(下划线)代替。
以纯文本形式编写节点
如果您使用文本编辑器编写 Yarn 脚本,则需要编写节点的标头。
[!信息] 如果您使用图形编辑器编写 Yarn 脚本(例如_Yarn Editor_),它会为您处理此问题,您可以跳过本节。
Yarn 节点的纯文本版本如下所示:
title: Node_Title
---
Here are some lines!
Wow!
===
在本例中,节点的标题是 Node_Title,它被设置在第一行 title 标头。您还可以添加所需的任何其他标头。
[!信息] 节点标头可以包含任意数量的具有 ** 结构的行
key: value**。这可用于存储附加信息,例如对话发生的位置。
这 --- 标记指示正文的开始位置。在此之后,您可以放置所有 Yarn 脚本。
这 === 标记表示节点结束的位置;在此之后,您可以开始另一个节点。
节点内容
节点的主体由三种不同类型的内容组成:lines、commands 和_options_。
线路
当您编写纱线纺纱机对话时,您在节点中编写的几乎每一行文本都是行。当一个节点运行时,它会运行每一行,一次一行,并将其发送到您的游戏。
对话行就是您希望某个实体或角色说出的内容,通常以说话的实体的名称开头。
例如,考虑 Night in the Woods 中的以下 Yarn 代码:
Mae: Well, this is great.
Mae: I mean I didn't expect a party or anything
Mae: but I figured *someone* would be here.
Mae: ...
Mae: Welcome home, Mae.
当这段代码在游戏中运行时,它看起来像这样:

Yarn Spinner 将这些行中的每一行发送到游戏,一次一行。游戏负责获取文本并将其呈现给玩家;在“林中之夜”的情况下,这意味着绘制对话气泡,为每个字母添加动画,然后等待用户按下某个键以前进到下一行。
对话行可以包含几乎任何文本,但 Yarn Spinner 用来向一行添加额外信息的一些特殊字符除外。
如果行首的冒号 (:) 之前有一组不带空格的字符,Yarn Spinner 会将其标记为字符的名称。然后,此信息将传递到您的游戏,以便您可以根据说台词的角色更改台词的显示方式。例如:
This is a line of dialogue, without a character name.
Speaker: This is another line of dialogue said by a character called "Speaker".
选项
当你想让玩家决定说什么时,你可以使用选项。选项可让您向玩家显示多条潜在的对话台词,并让玩家选择其中之一。
选项标有 -> 象征。您可以编写希望玩家看到的选项,然后玩家选择其中之一。该选项的内容与任何其他对话一样。
例如,考虑以下代码:
Companion: Hi there! What do you feel like doing today?
-> Player: I want to go swimming.
-> Player: I'd prefer to go hiking.
在此示例中,“嗨,您今天想做什么?”这一行会运行。然后玩家可以选择说“我想去游泳”或“我更喜欢去徒步旅行”。
选项和线路
快捷方式选项可以有自己的行,这些行在选择该选项时运行。如果选择不同的选项,它们将不会运行。要编写此内容,请_缩进_属于快捷方式选项的行。
在以下代码中,将根据选择的两个快捷方式选项中的哪一个来运行不同的行。
Companion: Hi there! What do you feel like doing today?
-> Player: I want to go swimming.
Companion: Okay, let's go swimming.
-> Player: I'd prefer to go hiking.
Companion: Cool, we'll go hiking then.
Player: Sounds good!
该脚本将以“嗨!你今天想做什么?”开始。然后玩家可以选择说“我想去游泳”或“我更喜欢去徒步旅行”。根据他们的选择,要么是“好吧,我们去游泳吧”,要么是“酷,那我们去徒步旅行吧”。最后,无论选择什么,“听起来不错!”这句话。会运行。
嵌套选项
除了包含行之外,选项还可以包含 other 选项。
Companion: Hi there! What do you feel like doing today?
-> Player: I want to go swimming.
Companion: Okay, let's go swimming.
Companion: Where do you want to swim?
-> Player: The lake!
Companion: Nice! It's a great day for it.
-> Player: The swimming pool!
Companion: Oh, awesome! I heard they installed a new slide.
-> Player: I'd prefer to go hiking.
Companion: Cool, we'll go hiking then.
Player: Sounds good!
您可以根据需要嵌套多个选项。然而,阅读起来可能有点困难。使用 <<jump>> 跳转到不同节点的命令:
标签:之前
title: Start
---
Companion: Hi there! What do you feel like doing today?
-> Player: I want to go swimming.
Companion: Okay, let's go swimming.
Companion: Where do you want to swim?
-> Player: The lake!
Companion: Nice! It's a great day for it.
-> Player: The swimming pool!
Companion: Oh, awesome! I heard they installed a new slide.
-> Player: I'd prefer to go hiking.
Companion: Cool, we'll go hiking then.
Player: Sounds good!
===
选项卡:之后
title: Start
---
Companion: Hi there! What do you feel like doing today?
-> Player: I want to go swimming.
Companion: Okay, let's go swimming.
<<jump Swimming>>
-> Player: I'd prefer to go hiking.
Companion: Cool, we'll go hiking then.
<<jump Hiking>>
===
title: Swimming
---
Companion: Where do you want to swim?
-> Player: The lake!
Companion: Nice! It's a great day for it.
-> Player: The swimming pool!
Companion: Oh, awesome! I heard they installed a new slide.
<<jump Done>>
===
title: Hiking
---
Companion: Have you got your hiking boots ready?
-> Player: Yes.
Companion: Great, let's go!
-> Player: No.
Companion: We can swing by your place and pick them up!
<<jump Done>>
===
title: Done
---
Player: Sounds good!
===
将对话片段分成节点可以帮助编写更整洁的文件,随着文件的增长,这些文件更容易编辑。
有时,所呈现的选项或选择不同选项的结果会根据玩家在此之前所做或所说的其他事情而变化,这是有意义的。这需要使用逻辑和变量,我们将在下一节中讨论。