Learn about once statements, which let you specify content that only runs once.
In Yarn Spinner 3, you can use a once
statement to run content only one time. When the script reaches a once
statement, it checks to see if it’s run before. If it has, it skips over it! Magic.
once
statements are great for making sure that the player never sees certain content more than once. For example, you might want a character to never introduce themselves to the player twice.
There are two main ways you can use a once
statement, which we'll explore below.
<<once>>
and <<endonce>>
:You can also use an <<else>>
clause within the <<once>>
statement, which will be run if the relevant <<once>>
content has already been seen:
You can also add an if
to the once
to run content a single time, but only when a certain condition is true. In all other cases, it will be skipped (or the else
content will be run, if there is any):
<<once>>
to a line, or options:If you add once
(or once if
) to a line, that line will only appear once, and will be skipped over every other time it’s encountered:
Similarly, if you add it to an option, that option will only be selectable once, and will be marked as unavailable after it’s been selected.
once
statements are really useful when you want to show long, detailed content the first time it’s encountered, but you don’t want to show it every time. This means that players don’t need to mash the ‘skip line’ button over and over when they realise that they’re starting to see a long run of lines they’ve already seen:
once
statements keep the information about whether they’ve been run or not in a variable that’s stored in your Dialogue Runner’s Variable Storage, just like any other variable. The variable isn’t directly accessible from your Yarn scripts.
This version of the documentation (docs.yarnspinner.dev/next) is for the current beta version of Yarn Spinner 3 (Beta 1). For Yarn Spinner 2.x, visit https://docs.yarnspinner.dev