Dynamic text lets you insert variables, game state, and computed values into your dialogue, making conversations feel personalized and responsive to the player’s actions.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/Rubonnek/dialogue-engine/llms.txt
Use this file to discover all available pages before exploring further.
Overview
The Dialogue Engine supports two ways to format dynamic text:- Format Operator (
%): GDScript’s built-in string formatting - Format Function (
String.format()): Dictionary-based formatting
Using the Format Operator (%)
The format operator is perfect for simple variable substitution:
Format Specifiers
| Specifier | Type | Example |
|---|---|---|
%d or %s | Integer/String | "You are level %d" |
%f | Float | "Temperature: %f°C" |
%.2f | Float (2 decimals) | "Price: $%.2f" |
%% | Literal % | "Success rate: %d%%" |
Using String.format()
The format function uses dictionaries for named placeholders:Dynamic Values with Callables
Callables let you compute values at display time, not when the dialogue is created:Callables are evaluated every time
get_formatted_text() is called, so the dialogue will always show the current value.Nested Data Structures
You can use nested arrays and dictionaries:Practical Examples
DialogueEntry Format Methods
| Method | Description |
|---|---|
set_format(data: Variant, operation_id: int) | Sets format data and operation |
get_format() -> Dictionary | Returns the format dictionary |
get_formatted_text() -> String | Returns text with formatting applied |
get_evaluated_format() -> Variant | Returns format data with callables evaluated |
has_format() -> bool | Returns true if format is set |
remove_format() | Removes format data |
Format Operation Constants
| Constant | Value | Description |
|---|---|---|
FORMAT_OPERATOR | 3 | Use % operator |
FORMAT_FUNCTION | 2 | Use String.format() |
FORMAT_NONE | 1 | No formatting (text as-is) |
Common Patterns
Updating values without recreating dialogue
Updating values without recreating dialogue
Use callables instead of static values:
Combining BBCode with formatting
Combining BBCode with formatting
You can use BBCode formatting alongside dynamic text:
Conditional text within dialogue
Conditional text within dialogue
Use callables to return different strings based on conditions:
Pluralization
Pluralization
Handle singular/plural forms dynamically:
Best Practices
- Always use
get_formatted_text()when you’ve set format data - Use callables for dynamic values that change during gameplay
- Cache expensive computations in your callable if needed
- Test edge cases like zero values, empty strings, and extreme numbers
- Consider localization - some languages may need different format strings
Next Steps
- Learn about save/load to persist dynamic data
- Check simple dialogue for BBCode formatting options
- See player choices to combine dynamic text with branching
