On this page
  1. Dialogue
  2. loaded, errors, has_node
  3. start, stop, running, node
  4. has_line, line, has_options, options, has_command, command
  5. advance
  6. choose
  7. on_command
  8. on_function
  9. wait, wait_until
  10. waiting
  11. variable, set_variable
  12. bind, visits
  13. save, load
  14. set_saliency
  15. Dialogue

rmp::Dialogue

class #include <rmp/dialogue.h> include/rmp/dialogue.h:224
class Dialogue

A conversation: a compiled Yarn script, where it is in it, and what it remembers. It draws nothing — the presenters of rmp/ui.h do, or the game. Moved, never copied.

Dialogue

Dialogue()

No script: loaded() is false

loaded, errors, has_node

bool loaded() const
std::span<const std::string> errors() const
bool has_node(std::string_view node) const

Whether a script is loaded and compiled; when not, errors() says why, a line each, as file:line:column: what is wrong.

start, stop, running, node

bool start(std::string_view node = "Start")
void stop()
bool running() const
std::string node() const

Run from a node's first line. False when there is no such node.

running: Started, not yet finished

node: The node it is in, or empty

has_line, line, has_options, options, has_command, command

bool has_line() const
const DialogueLine &line() const
bool has_options() const
std::span<const DialogueOption> options() const
bool has_command() const
std::string_view command() const

What it is waiting for: a line to be read, a choice, or a command the game did not handle. Nothing of the three when it is not running.

line: Empty when there is none

command: Its text, {expressions} filled

advance

void advance()

On, past the line or the command.

choose

void choose(int index)

The option chosen, by its place in options(). When none is available, any number goes on past the options.

on_command

template <class F> void on_command(std::string_view name, F &&handler)

<<name arg arg>> calls handler, and the dialogue goes on by itself — or waits, when the handler calls wait() or wait_until(). A command nobody handles waits in has_command().

Typed: each word after the name arrives as the parameter asks, and a script that gives the wrong number of words, or a word that is not a number where one goes, is a mistake said once, the command not run:

talk.on_command("walk", [&](std::string who, float speed) { ... });
talk.on_command("shake", [&] { camera.shake(); });

Or every word as written: [&](std::span<const std::string> words) { ... }.

on_function

template <class F> void on_function(std::string_view name, F &&function)

name(...) in an expression. Typed: the parameters say what it takes and the result what it gives, and a call with the wrong number or kind of arguments is a mistake said once, never a call:

talk.on_function("has_item", [&](std::string item) -> bool { ... });

Or untyped: [&](rmp::DialogueValue &out, std::span<const rmp::DialogueValue> args). Write the result type (-> bool): rmp yarn ysls reads it for the editor.

wait, wait_until

void wait(float seconds)
template <class F> void wait_until(F &&done)

From inside a command's handler: the dialogue waits after the command, for seconds, or until done() is true (asked once a frame, from waiting()). <<wait 2>> waits by itself, when the game has no "wait".

talk.on_command("walk", [&](std::string where) {
    mika.walk_to(where);
    talk.wait_until([&] { return mika.arrived(); });
});

waiting

bool waiting()

Whether a command holds the dialogue: no line, no options, until its wait is over. Asking is what moves it on: once a frame, the presenters do it, or the game's own loop.

variable, set_variable

DialogueValue variable(std::string_view name) const
void set_variable(std::string_view name, const DialogueValue &value)

$variables: what the script set, and what the game sets for it.

bind, visits

void bind(std::string_view name, int &variable)
void bind(std::string_view name, float &variable)
void bind(std::string_view name, bool &variable)
void bind(std::string_view name, std::string &variable)
void bind(std::string_view name, rmp::Callback<DialogueValue &> get, rmp::Callback<const DialogueValue &> set)
int visits(std::string_view node) const

A $variable that IS one of the game's: the script reads it and writes it, and nothing is copied. The script declares it, with its type (<<declare $gold = 0>>); a binding of another type, or of a variable the script does not declare, is a mistake said once. save() leaves bound variables out: they are the game's to save. The variable must outlive the dialogue.

talk.bind("$gold", player.gold);

visits: Visited_count()

save, load

void save(rmp::Value &out) const
void load(const rmp::Value &in)

Everything the conversation remembers — variables, visits, what was seen once — into an rmp::Value for rmp::save, and back.

set_saliency

void set_saliency(DialogueSaliency saliency)

How line groups and node groups choose; LEAST_SEEN unless set.

Dialogue

explicit Dialogue(std::unique_ptr<detail::DialogueState> state)

The script's own: for the loaders below.