← All scene elements
SCENE ELEMENT / 16

Interactive dialog

Branching dialogs driven by media and player input.

LIVE WEB PLAYER

See it respond.

The same raylib runtime, compiled to WebAssembly. Load this example, inject MQTT messages and watch its published events.

Loading WebAssembly…
MQTT I/O
Waiting for runtime…

The browser requires a user action before the scene is loaded. Click Load demo scene first. MQTT is emulated and never leaves this page. Shaders are disabled in the web build; GPIO is hardware-only.

Orchestrates classic adventure-style dialog: intro, up to N visible choices, question/answer playback, conditional choices and idle timeout. Inputs may be visible button elements, keypress elements, GPIO inputs, or a mixture.

Component configuration

FieldDefaultDescription
typerequiredinteractive_dialog
fileemptyMetadata JSON from media/assets/
autoplayfalseStart whenever the containing scene activates
media_element_idrequiredAudio visualizer or video element ID
choice_input_idsrequiredOrdered input IDs mapped to A, B, C…
cancel_input_idemptyInput that closes the dialog
timeout_seconds60Idle timeout; 0 disables it
content_fontfallback fontIntro/question/answer TTF
content_font_sizefont_sizeContent size
choice_fontcontent fontChoice TTF
choice_font_sizecontent sizeChoice size
font, font_sizebuilt-in / 28Backward-compatible font fallbacks
line_spacing6Additional pixels between content lines

Copy-and-paste scene JSON

json
{
  "type": "interactive_dialog",
  "id": "interview_dialog",
  "pos": [160, 570],
  "size": [1600, 400],
  "file": "dialog-example.json",
  "autoplay": true,
  "media_element_id": "dialog_audio",
  "choice_input_ids": [
    "choice_a",
    "choice_b",
    "choice_c",
    "choice_d"
  ],
  "cancel_input_id": "dialog_cancel",
  "timeout_seconds": 60,
  "content_font": "_decterm.ttf",
  "content_font_size": 32,
  "choice_font": "Technology.ttf",
  "choice_font_size": 34,
  "line_spacing": 8,
  "layer": 2
}

Metadata configuration

FieldDescription
intro_text, intro_audioIntro display and clip
options[].idStable option ID used by conditions
labelChoice-menu label
question, answerDisplayed content
question_audio, answer_audioSeparate clips
audioOne combined question+answer clip
importantRequired before automatic completion
repeatableKeep option available after asking
show_afterShow only after all listed IDs were asked
hide_afterHide after any listed ID was asked

question_audio without answer_audio is treated as one combined clip.

json
{
  "intro_text": "Choose a question.",
  "intro_audio": "intro.wav",
  "options": [
    {
      "id": "A1",
      "label": "Where were you last night?",
      "question": "Where were you last night?",
      "answer": "I was at home.",
      "audio": "a1_combined.mp3",
      "important": true,
      "repeatable": false,
      "show_after": [],
      "hide_after": []
    }
  ]
}

MQTT

text
ergs/rpi01/cmd/interview_dialog/open      dialog-example.json
ergs/rpi01/cmd/interview_dialog/file      dialog-example.json
ergs/rpi01/cmd/interview_dialog/play      ON
ergs/rpi01/cmd/interview_dialog/play      OFF
ergs/rpi01/cmd/interview_dialog/close     1

open/file load metadata and start immediately. The dialog also stops on cancel, timeout, no remaining options, all important options asked, or scene deactivation.