# rmp::Dialogue

> A conversation: a compiled Yarn script, where it is in it, and what it remembers.

Source: https://omardev29.github.io/rmp-docs/reference/classes/rmp-Dialogue.html

class `#include <rmp/dialogue.h>` [include/rmp/dialogue.h:224](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/dialogue.h#L224-L383)

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()

function [include/rmp/dialogue.h:226](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/dialogue.h#L226)

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

function [include/rmp/dialogue.h:235](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/dialogue.h#L235)

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

function [include/rmp/dialogue.h:240](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/dialogue.h#L240)

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

function [include/rmp/dialogue.h:247](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/dialogue.h#L247)

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()

function [include/rmp/dialogue.h:255](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/dialogue.h#L255)

On, past the line or the command.

### `choose`

void choose(int index)

function [include/rmp/dialogue.h:258](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/dialogue.h#L258)

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)

function [include/rmp/dialogue.h:270](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/dialogue.h#L270-L289)

<<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:

```cpp
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)

function [include/rmp/dialogue.h:297](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/dialogue.h#L297-L317)

`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:

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

Or untyped: [&]([`rmp::DialogueValue`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-DialogueValue.html) &out, std::span<const [`rmp::DialogueValue`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-DialogueValue.html)> 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)

function [include/rmp/dialogue.h:326](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/dialogue.h#L326)

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".

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

### `waiting`

bool waiting()

function [include/rmp/dialogue.h:336](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/dialogue.h#L336)

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)

function [include/rmp/dialogue.h:339](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/dialogue.h#L339)

$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

function [include/rmp/dialogue.h:349](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/dialogue.h#L349)

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()`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-save.html) leaves bound variables out: they are the game's to save. The variable must outlive the dialogue.

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

`visits`: `Visited_count()`

### `save`, `load`

void save(rmp::Value &out) const

void load(const rmp::Value &in)

function [include/rmp/dialogue.h:360](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/dialogue.h#L360)

Everything the conversation remembers — variables, visits, what was seen once — into an [`rmp::Value`](https://omardev29.github.io/rmp-docs/reference/classes/rmp-Value.html) for [`rmp::save`](https://omardev29.github.io/rmp-docs/reference/namespaces/rmp-save.html), and back.

### `set_saliency`

void set_saliency(DialogueSaliency saliency)

function [include/rmp/dialogue.h:364](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/dialogue.h#L364)

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

### `Dialogue`

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

function [include/rmp/dialogue.h:367](https://github.com/omardev29/raylib_multiplatform/blob/982bf2a1e307c49776bff84211260703b8de6895/include/rmp/dialogue.h#L367)

The script's own: for the loaders below.
