A Different Kind of Presenter
The Presenter on Building Your Own Presenter works a lot like the built-in ones, showing one line at a time and options as buttons. A Presenter only has to show a line and return when it’s done, and show options and return the one the player picked. How it does those two things is up to you.
The Presenter on this page uses the same two functions to keep the whole conversation on screen as a transcript, like a text adventure. Nothing is cleared, and each line is added under the last for the player to read back through. Options are listed as numbered lines in the transcript, and the player picks one with the number keys: 1 for the first option, 2 for the second, and so on. The numbered options stay in the transcript after the player has picked, and the option they chose is written after a >.
The scene
The whole Presenter uses one RichTextLabel. Turn on its Scroll Following property to make it scroll down as the transcript grows.
- Add a
NodecalledTranscriptPresenter, and attach the script below to it. - Set its Transcript property to the
RichTextLabel. - Add
TranscriptPresenterto the Dialogue Runner’s Presenters list. It handles both lines and options, and can be the only Presenter.
The script
class_name TranscriptPresenter
extends YarnDialoguePresenter
signal _option_chosen(index: int)
@export var transcript: RichTextLabel
var _choices: Array[int] = []
func _unhandled_input(event: InputEvent) -> void:
if _choices.is_empty():
if event.is_action_pressed("ui_accept"):
dialogue_runner.request_next_content()
return
if event is InputEventKey and event.pressed:
var number: int = event.keycode - KEY_1
if number >= 0 and number < _choices.size():
_option_chosen.emit(_choices[number])
func run_line(
line: YarnLine,
token: YarnCancellationToken = null
) -> void:
transcript.append_text(YarnMarkupParser.escape_text(line.text) + "\n\n")
await token.wait_for_next_content()
func run_options(
options: Array[YarnOption],
token: YarnCancellationToken = null
) -> int:
if token.is_next_content_requested:
return -1
_choices.clear()
for i in options.size():
if not options[i].is_available:
continue
_choices.append(i)
var number := str(_choices.size()) + ". "
transcript.append_text(number + options[i].text + "\n")
var give_up := _option_chosen.emit.bind(-1)
token.next_content_requested.connect(give_up)
var index: int = await _option_chosen
token.next_content_requested.disconnect(give_up)
_choices.clear()
if index >= 0:
var picked := options[index].text
transcript.append_text("\n> " + picked + "\n\n")
return indexRichTextLabel the transcript is written to._choices[0], and so on. It’s empty the rest of the time.ui_accept moves on to the next line, the same as the simple Presenter.KEY_1 to KEY_9 are next to each other, subtracting KEY_1 turns the key into 0 to 8.append_text reads BBCode, and escape_text stops brackets in the line being read as tags. Nothing is ever removed.-1 straight away.>, and return its index.What stayed the same
What this Presenter gives back to the Dialogue Runner is the same as the simple Presenter. run_line returns once the player has moved on, and it makes no difference to the Dialogue Runner that the line is still on screen. run_options returns the index of the chosen option in the array it was given, or -1. The number the player pressed is only the option’s position on screen, and _choices turns it back into that index. Both functions give up when the token says the dialogue is moving on.
Included with Yarn Spinner+
Snaaake
A ready-made radio conversation in the style of classic action games, with talking portraits, voice-over and subtitles.
Included with Yarn Spinner+
Classic RPG
A ready-made dialogue box in the style of old-school RPGs, with a typewriter you can speed up, pause and skip.