Once
Learn about once statements, which let you specify content that only runs once.
Sometimes it's useful to create lines of dialogue that can only ever be displayed once.
In Yarn Spinner Scripts, you can use a once statement to denote content that can only be run one single 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.
There are two main ways you can use a once statement, which we'll explore below.
You can wrap some lines in <<once>> and <<endonce>>:
<<once>> and <<endonce>>:<<once>>
// The guard will introduce herself to the player only once.
Guard: Hail, traveller! Well met.
Guard: I am Alys, the guard!
<<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:
<<once>>
Guard: Hail, traveller! Well met.
<<else>>
Guard: Welcome back.
<<endonce>>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):
You can add <<once>> to a line, or options:
<<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:
Last updated
Was this helpful?
