绕行命令

除了使用 jumps.md 要在节点之间移动,您还可以使用 detour 命令。

一个 detour 命令看起来与跳转非常相似:它需要一个参数,其中包含要移动到的节点的标题,但与跳转命令不同,绕行命令将返回到之后调用它的节点。

使用绕行命令

绕行命令的工作方式与跳转命令非常相似,不同之处在于它会在完成绕行后返回到它所绕行的节点。这是一个实际的例子:

title: Guard
---
Guard: Have I told you my backstory?
 
-> Yes.
	Guard: Oh. Well, then.
-> No?
	<<detour Guard_Backstory>>
 
Guard: Anyway, you can't come in.
===
 
title: Guard_Backstory
---
Guard: It all started when I was a mere recruit.
// (five minutes of exposition omitted)
===

如果玩家回复 No? 对于警卫的问题,Yarn Spinner 将绕道至标题为 Guard_Backstory 并运行其内容。

当结束时 Guard_Backstory 到达节点后,Yarn Spinner 将返回到标题为 Guard,并从紧接之后恢复 detour 陈述。

将 Detour 与 Return 命令结合使用

当你 detour 到一个节点中,Yarn Spinner 运行该节点中的内容,就像您使用 jump 陈述。当你到达节点的末尾,或者到达一个 return 命令后,纺纱机将返回到 detour 命令。返回命令看起来像 <<return>>。没有参数。

您可以使用以下命令从绕行的节点提前返回 return 命令。这样做将返回到刚刚 detour 命令就像已到达节点末尾一样,例如:

title: Guard
---
Guard: Have I told you my backstory?
 
-> Yes.
	Guard: Oh. Well, then.
-> No?
	<<detour Guard_Backstory>>
 
Guard: Anyway, you can't come in.
===
 
title: Guard_Backstory
---
Guard: Do you want the detailed version or the short version?
 
-> Detailed.
	<<detour Guard_Detailed_Backstory>>
	Guard: I hope you enjoyed learning all that.. Anyway...
-> Short.
	Guard: Right, well, I was a recruit, then I wasn't.
===
 
title: Guard_Detailed_Backstory
---
Guard: It all started when I was a mere recruit.
 
// (five minutes of exposition omitted)
// (other stuff happens)
 
Guard: Want to hear more?
 
-> Yes.
-> No.
	<<return>>
 
Guard: (speaks more garbage)
===

[!信息] 如果纺纱厂达到 return 命令,并且它没有绕道另一个节点,它将停止对话(也就是说,它的行为就像你写了一个 stop 命令。)

当您绕行到一个节点时,该节点本身可以​​绕行到_其他_节点。如果绕行节点使用 jump 命令运行另一个节点,返回堆栈被清除。如果你 detour 进入一个节点,并且该节点 jumps 到另一个节点,Yarn Spinner 不会返回到原来的状态 detour 地点。

此代码段中的绕行和返回流程(自动并由返回命令触发)。

当你使用 <<detour>> 命令,它们将在 Visual Studio Code 的 Yarn Spinner 的图形视图中显示为两端各有一个箭头的线,从绕行的节点到绕行的节点:

<> 命令在图形视图中可视化。

编写一些绕行命令

步骤1

写一个有几个节点的简单故事。

以合理的方式将您的故事分散到各个节点上。

步骤2

使用 <<detour>> 在故事中的节点之间移动的命令。

确保在每个节点中指定要跳转到的节点的名称 <<detour>> 命令。

步骤3

使用预览运行您的故事。

尝试一下,并确保迂回的行为符合您的预期。

接下来,了解一下 logic-and-variables.md 在纺纱厂脚本中。