一次

有时,创建只能显示一次的对话行很有用。

在纱线纺纱机脚本中,您可以使用 once 语句来表示只能运行一次的内容。当脚本达到 once 语句,它检查之前是否运行过。如果有,它会跳过它!魔法。

[!信息] once 声明非常有助于确保玩家不会多次看到某些内容。例如,您可能希望角色永远不会向玩家介绍自己两次。

您可以通过两种主要方式使用 once 声明,我们将在下面探讨。

在 Try Yarn Spinner 中运行此示例

您可以将一些行换行成 <<once>><<endonce>>:

<<once>>
  // The guard will introduce herself to the player only once. 
  Guard: Hail, traveller! Well met.
  Guard: I am Alys, the guard!
<<endonce>>

您还可以使用 <<else>> 内的条款 <<once>> 语句,如果相关则运行该语句 <<once>> 内容已经看过:

<<once>>
  Guard: Hail, traveller! Well met.
<<else>>
  Guard: Welcome back.
<<endonce>>

您还可以添加一个 ifonce 仅当特定条件成立时才运行内容一次。在所有其他情况下,它将被跳过(或 else 将运行内容(如果有):

<<once if $player_is_adventurer>>
  // The guard knows the player is an adventurer, so say this line, 
  // but only ever once!
  Guard: I used to be an adventurer like you, but then I took an arrow in the knee.
<<else>>
  // Either the player is not an adventurer, or we already saw the 
  // 'arrow in the knee' line.
  Guard: Greetings.
<<endonce>>

您可以添加 <<once>> 到一行或选项:

如果你添加 once (或者 once if) 到一行,该行只会出现一次,并且每次遇到它都会被跳过:

Guard: Who are you? <<once>> // Show this line only one time
Guard: Go on, get lost!

同样,如果将其添加到某个选项,则该选项只能选择一次,并且在选择后将被标记为不可用。

-> What's going on? <<once>>
	Guard: The kingdom is under seige!
-> Where can I park my horse? <<once if $has_horse>>
	Guard: Over by the tavern.
-> Lovely day today!
	Guard: Uh huh.
-> I should go.
	Guard: Please do.

once 当您想在第一次遇到时显示长而详细的内容,但又不想每次都显示时,语句非常有用。这意味着当玩家意识到他们开始看到一长串他们已经看过的线时,他们不需要一遍又一遍地按下“跳过线”按钮:

<>
 // 第一次显示长的、塑造角色的台词
	警卫:没有什么新的报告!
	警卫:我已经在这个岗位呆了几个小时了,我很无聊。
	警卫:我已经等不及值班结束了。
<<其他>>
	// 其他时间都显示更简洁的版本
	警卫:没什么可报告的!
<<结束>>

[!信息] once 语句将有关它们是否已运行的信息保留在存储在 Dialogue Runner 的变量存储中的变量中,就像任何其他变量一样。该变量无法从 Yarn 脚本直接访问。