Dialogue System
The Gorilla3D Dialogue System provides a multi-level, event-driven dialogue framework for building interactive conversations in games. It supports branching dialogues with questions, answers, flow nodes, character definitions, timed events, and full serialization to JSON.
Table of Contents
- Overview
- Core Concepts
- Getting Started
- Dialogue Structure
- Events
- Characters
- Runtime Execution
- Loading and Saving
- Best Practices
Overview
| Class | Description |
|---|---|
TGorillaDialogueSystem |
Main component managing dialogues and characters |
TGorillaDialogue |
A single dialogue (conversation) |
TGorillaDialogueItem |
A node in the dialogue tree (question, answer, or flow) |
TGorillaDialogueItemEvent |
An event attached to a dialogue item |
TGorillaDialogueCharacter |
A character participating in dialogues |
Core Concepts
Item Kinds
| Kind | Description |
|---|---|
Question |
A decision point — displays text and waits for player choice |
Answer |
An option the player can select |
Flow |
A chain element connecting questions and answers |
Reference |
A redirect to another dialogue item |
Event Kinds
Events can be attached to dialogue items and triggered at specific moments:
| Kind | Description |
|---|---|
Text |
Display text on screen |
Image |
Show an image |
Audio |
Play an audio file |
Video |
Play a video |
Animation |
Start an animation |
Method |
Execute a published method via RTTI |
ObjProperty |
Set an object property |
Redirect |
Jump to another item |
Timer |
Start a timeout counter |
Misc |
Custom user-defined event |
Event Triggers
| Trigger | Description |
|---|---|
OnBegin |
Executed when the item is displayed |
OnEnd |
Executed when the item is hidden |
OnTimeout |
Executed when a timer expires |
Getting Started
Design-Time
- Drop a
TGorillaDialogueSystemonto your form - Use the dialogue editor (IDE integration) to create dialogues visually
- Define characters, questions, answers, and events in the flow chart
Runtime
var
DlgSys: TGorillaDialogueSystem;
begin
DlgSys := TGorillaDialogueSystem.Create(Self);
// Load a dialogue from file
// Use Gorilla.Utils.Dialogue.Reader to load JSON files
end;
Dialogue Structure
A typical dialogue tree looks like this:
Dialogue: "Guard Conversation"
├── Question: "What do you want?"
│ ├── Answer: "I need to pass" → Flow → Question: "Do you have a permit?"
│ │ ├── Answer: "Yes" → [end]
│ │ └── Answer: "No" → [redirect to start]
│ └── Answer: "Nothing, sorry" → [end]
└── Events:
├── OnBegin: Text "A guard approaches you"
└── OnBegin: Audio "guard_greeting.wav"
Events
Each dialogue item can have multiple events:
// Events are configured per item
// Event triggers: OnBegin, OnEnd, OnTimeout
// Event kinds: Text, Image, Audio, Video, Animation, Method, ObjProperty, Redirect, Timer, Misc
The dialogue system supports:
- Variables (
TGorillaDialogueVariables): StoreTObjectreferences by name for cross-dialogue state - Parameters (
TGorillaDialogueParameters): Store dynamic key-value pairs for item configuration
Characters
Characters represent speakers in the dialogue:
// Characters are managed in the TGorillaDialogueCharacterCollection
// Each character has an identifier and can be linked to dialogue items
Runtime Execution
Callbacks
| Event | Type | Description |
|---|---|---|
OnStartDialogue |
TOnStartDialogue |
Dialogue begins, provides initial items |
OnStopDialogue |
TOnStopDialogue |
Dialogue ends |
OnPauseDialogue |
TOnPauseDialogue |
Dialogue is paused |
OnBeginDialogueItem |
TOnBeginDialogueItem |
An item is displayed (with available choices) |
OnEndDialogueItem |
TOnEndDialogueItem |
An item is dismissed |
OnBeginItemEvent |
TOnBeginDialogueItemEvent |
An event starts (can set AHandled) |
OnEndItemEvent |
TOnEndDialogueItemEvent |
An event finishes |
OnSkippedDialogue |
TOnSkippedDialogue |
Player skipped dialogue |
OnSkipAvailability |
TOnSkipAvailability |
Notification if skip is available |
OnBeginItemTimeout |
TOnBeginItemTimeout |
Timeout counter starts |
OnEndItemTimeout |
TOnEndItemTimeout |
Timeout expired |
Loading and Saving
The dialogue system uses JSON for serialization:
Gorilla.Utils.Dialogue.Reader— Loads dialogues from JSONGorilla.Utils.Dialogue.Writer— Saves dialogues to JSON
Dialogues can also be managed via the Assets Manager as DIALOGUE asset type.
Best Practices
- Use the flow chart editor (IDE) for visual dialogue design
- Keep dialogues modular — split long conversations into separate dialogue objects
- Use References to link between dialogues for reusable dialogue segments
- Use Timer events with
OnTimeoutfor timed choices (e.g., "respond in 5 seconds") - Use Variables to track dialogue state across multiple conversations
- Use Parameters for dynamic content (NPC names, quest details)
- Integrate with the Assets Manager by storing dialogue files in
DIALOGUEasset packages
See Also
Related Topics
- Audio — Playing the audio referenced by
Audioevents - Text-to-Speech — Speaking dialogue lines instead of playing recorded files
- Speech-to-Text — Letting the player answer by voice
API Reference
- Gorilla.Utils.Dialogue.System — Full API documentation