DialogueTextLabel is an extension of Godot's RichTextLabel
, designed for advanced dialogue systems of all kinds.
Originally built for my own game, CHORDIOID, this script is a stripped-down, more modular version of that cluttered mess.
It handles the logistical nightmare of displaying text with embedded commands and formatting properly, so you can focus on the other nightmare of creating a half-decent backend that feeds the lines into the label in the first place.
- Escape sequences. This one's pretty self-explanatory.
- "Typewriter" effect: Lines are automatically presented one character at a time, with customizable speeds
- Robust embedded command system:
- Insert pauses, text speed changes, calls to other Nodes, all embedded in the text with a simple
{curly brace}
syntax - Works in harmony with BBCode, and adds the ability to use escape sequences on both
- Inline expression evaluation
- Toggleable automatic pauses after punctuation
- Insert pauses, text speed changes, calls to other Nodes, all embedded in the text with a simple
- Integration with your systems:
- Using the group
dia_event
, Nodes can register themselves to receive calls todia_event(name, args)
whenever the{event}
command is used in dialogue. - Use the
expression_base_node
property to expose your own variables and functions to the expression system.
- Using the group
Use set_new_text(new_line: DialogLine)
to start a new line. DialogLine
is a class defined in the script that looks like this:
If you want a text advance sound, hook up an AudioStreamPlayer
via the exported voice_player
property.
BBCode is BBCode. Works how you'd expect, except that tags can be escaped using backslashes now.
And then there's commands.
A command is, to use the technical term, a Thing That Happens When A Certain Character Is Reached. They're used for pauses, text speed changes, and whatever else your heart desires. Commands are entered between {curly braces}
. The standard syntax for a command is {name arg}
, where arg
is an expression. See the definition of handle_command()
for all the available commands.
The event command has a slightly different syntax; more akin to your average function call. The full syntax is {event event_name(arg1, arg2, ...)}
, or {event await event_name(arg1, arg2, ...)}
, depending on the behaviour you want (see process_event()
). Worth noting is that event
, like most commands, has an abbreviation: e
.
For a practical example, here are the strings used for the showcase below:
var lines = [
"This is a DialogueTextLabel demonstration!",
"Look, I can use [color=yellow]BBCode[/color], or \\[color=yellow]escape it[/color]!",
"Autopunc is on, which automatically puts pauses after punctuation.",
"But you can also do it{p 20} manually!",
"As for the event system...{p 10} Walter, would you help me demonstrate? {e walterify()}",
"Thank you. Now, then: Watch as I turn Walter White... into Walter Wide{e wideify(2.0)}.",
"As you can see, anything's possible with the event system! Thank you, Walter.{e dewalterify()}",
]
Makes sense? Makes sense.
Figure 1: graphic design is my passion
Figure 2: they wont tell you what bbcode stands for but i know. it stands for bo-
Figures 3, 4: i dont have a funny joke for these ones. its just a neat feature
Listen. Bucko. I'm no lawyer, nor a cop.
I could put this thing up as MIT, or BSD, or what have you. But I'm not about to slam you with a C&D for not including the right copyright notice for my 500-line Godot script. Do what you want, I'm not your mom.
That said, if you do use this in your game, just credit me in some reasonable way.
I WILL cry.