Add-ons / <<dlg>> Multi-Level Dialog

Shows multi-level dialog options. It will show the player all lines from the top level. After player chooses a line, the next level of dialog is displayed.

Author hogart
Website https://github.com/hogart/sugar-cube-utils#dlg-level-and-line
Story format SugarCube 2
Last checked Thu Sep 03 2020
License MIT License
Download dlg.zip

Index

Overview

<<dlg>> is split into <<level>>s, which, in turn, consist of <<line>>s. It will show the player all lines from given level. After player chooses a line, line's content gets appended and next level is displayed.

::Start
— Hi!

<<dlg "dlg" 0 "➤">>\
    <<level 0>>\
        <<line "— How are you" "☺ ">>
            — Hi, how are you?
            — Everything's great! You?
        <</line>>
        <<line "— Hi!" "👋 ">>
            — Hi!
            — How are you?
        <</line>>
    <</level>>\
    <<level 1>>\
        <<line "— Things are tough" "😢 ">>
            — Things are tough, my pet hamster just died!:(
        <</line>>
        <<line "— Things are fine..." "❤ ">>
            — Things are fine, wanna hang out?
        <</line>>
        <<line "— Time to go...">>
            — Sry, playing new game, talk later!
        <</line>>
    <</level>>
<</dlg>>

Macros

<<dlg>>

<<dlg>>

Syntax: <<dlg ["id" starting-level "prefix"]>>

Arguments:

Additionally, the macro behavior can be fine-tuned by changing the options passed into the script: {trim: false, append: false}. Setting trim to true will force <<line>> to trim its contents before displaying (no unneeded line breaks). Setting prepend to true will make <<line>> to prepend this line's visible part to the contents before displaying. There will be linebreak between the visible part and the contents.

Usage:

<<dlg "dlg" 0 "➤">>\
  <<level 0>>\
    <<line "— How are you" "☺ ">>
      — Hi, how are you?
      — Everything's great! You?
    <</line>>
    <<line "— Hi!" "👋 ">>
      — Hi!
      — How are you?
    <</line>>
  <</level>>\
  <<level 1>>\
    <<line "— Things are tough" "😢 ">>
      — Things are tough, my pet hamster just died!:(
    <</line>>
    <<line "— Things are fine..." "❤ ">>
      — Things are fine, wanna hang out?
    <</line>>
    <<line "— Time to go...">>
      — Sry, playing new game, talk later!
    <</line>>
  <</level>>
<</dlg>>

READ: Documentation

<<level>>

<<level>>

Syntax: <<level level>>

<<level>> accepts single numeric mandatory argument: its level.

Usage: See <<dlg>>.

READ: Documentation

<<line>>

<<line>>

Syntax: <<line "line" ["prefix" level]>>

Arguments:

Usage: See <<dlg>>.

READ: Documentation

Live demo

Demo Twee code:

:: Start
— Hi!
<<dlg "dlg" 0 "➤">>\
	<<level 0>>\
		<<line "— How are you?" "🙂 ">>
			— //Hi, how are you?//
			— Everything's great! You?
		<</line>>
		<<line "— Hi!" "👋 ">>
			— //Hi!//
			— How are you?
		<</line>>
	<</level>>\
	<<level 1>>\
		<<line "— Things are tough" "😢 ">>
			— //Things are tough, my pet hamster just died! :(//
		<</line>>
		<<line "— Things are fine..." "💖 ">>
			— //Things are fine, wanna hang out?//
		<</line>>
		<<line "— Time to go...">>
			— //Sry, playing new game, talk later!//
		<</line>>
	<</level>>\
<</dlg>>\