Examples & Tutorials

These examples demonstrate DVN features in increasing complexity. You can copy them directly or build upon them for your own project.
Contents
- Preview
- Beginner
- Hello World
- Basic Character Dialogue
- Text Styling
- Choices (Simple Branching)
- Play a Sound Effect
- Scene Navigation
- Basic UI Theme Change
- Intermediate
- Branching Narrative With Variables
- Conditional Dialogue
- Save/Load Tutorial
- Custom Character Expressions
- Effects Chain Example
- Simple Animation/Movement
- Timed Narrative Events
- Basic UI Modification
- Importing JSON or CSV
- Randomized Narrative Events
- Advanced (Power Users)
- State-Based Story Navigation
- Minigame / Interaction (Custom Gameplay)
- Inventory System
Preview
You can download a preview of most examples and run it directly without building DVN.
Download: https://github.com/ProjectDVN/Examples/archive/refs/heads/main.zip
Repository: https://github.com/ProjectDVN/Examples/
Beginner
Below are some beginner examples of using DVN.
Hello World
Hello World in DVN is just a couple of lines long.
You can put this script into a script file and it will work instantly, for example data/game/scripts/main.vns
[main]
Hello, World!
Basic Character Dialogue
In this example, we're going to render two characters and have them speak using alternating dialogue lines.
This assumes you already understand the basics of defining characters and loading their sprite assets.
The two characters we'll be using are:
- Bob - the main character (off-screen but speaking)
- Alice - a character visible on screen
When run, DVN displays each line one after another. The left side (e.g., Bob or Alice) is the speaker name, and the text after = is what they say.
[main]
c=Alice
Bob=How are you, Alice?
Alice=I'm fine, how are you?
Bob=Fantastic!
Alice=That's good to hear.
Text Styling
Text styling such as bold or italic in DVN is typically handled by using separate font files for each style. For example:
data/fonts/calibri.ttf (Original)
data/fonts/calibrib.ttf (Bold)
data/fonts/calibrii.ttf (Italic)
data/fonts/calibriz.ttf (Bold + Italic)
Text Color
Text color can be controlled in two ways:
- Directly through UI component properties (for example. .color or .textColor depending on element type)
- Globally in game/settings.json
"defaultTextColor": "",
"buttonTextColor": "fff",
"dropdownTextColor": "fff",
"textBoxTextColor": "fff",
If defaultTextColor is not set, DVN will fall back to "fff" (white).
Note: Some UI elements may override the global text color depending on their configuration or theme. If colors don't change as expected, check the UI element's settings.
Choices (Simple Branching)
Choices in DVN are created using the option command (or its shorthand o). Each option points to another scene or section in the script.
[main]
Do you like DVN?
yes -> Yes
no -> No
[yes]
Yay!
[no]
Aw! :(
When the player makes a selection, DVN jumps to the matching label ([yes] or [no]) and continues the story from there.
Play a Sound Effect
This example assumes you already know how to register sound paths in music.json. If not, see the Multimedia section first.
Sound effects or ambience can be played using the sound command (or its shorthand s).
music.json:
{
"Bob_Relief": "data/game/sounds/bob_relief.wav",
"Raining": "data/game/sounds/raining.wav"
}
main.vns:
[main]
bg=Sunny
s=Bob_Relief
Bob:raining=Today sure is sunny.
[raining]
bg=Raining
s=Raining
Bob=Why did it start raining?!
When the scene runs, the first sound plays immediately. Moving to the next label ([raining]) changes the background and switches the audio to the rain ambience.
# Try replacing "s=" with "sound=" to see the long form syntax.
# Example:
sound=Bob_Relief
Scene Navigation
There are two ways to move between in scenes in DVN.
- Setting a jump state on a text entry.
[main]
t:next-scene=We will go to next scene after this.
[next-scene]
This is the next scene.
When the first scene has finished then the next scene will be displayed.
- Setting a jump state on an option
[main]
What scene do you wanna go to?
o:sunny=Sunny
o:raining=Raining
[sunny]
It is sunny!
[raining]
It is raining!
When you choose either option Sunny or Raining then it will go to the respective scenes.
Basic UI Theme Change
You can change a lot of UI theme settings in data/settings.json such as button colors, dropdown colors, textbox colors, default text colors etc.
Example:
"defaultTextColor": "fff",
"dialoguePanelBackgroundColor": "52be80",
"dialoguePanelBorderColor": "27ae60",
"namePanelBackgroundColor": "52be80",
"namePanelBorderColor": "27ae60",
"buttonTextColor": "fff",
"buttonBackgroundColor": "7dcea0",
"buttonBackgroundBottomColor": "52be80",
"buttonBorderColor": "27ae60",
"dropdownTextColor": "fff",
"dropDownBackgroundColor": "7dcea0",
"dropDownBorderColor": "27ae60",
"checkBoxBackgroundColor": "7dcea0",
"checkBoxBorderColor": "27ae60",
"textBoxColor": "7dcea0",
"textBoxTextColor": "fff",
"textBoxBorderColor": "27ae60"
Note: some entries might not be in your settings.json, but you can safely add them.
Note: All colors are in hex values, such as fff being white.
Intermediate
Below are some intermediate examples of using DVN.
These mostly assume you understand the basics of DVN.
Branching Narrative With Variables
In this example, the player makes a choice and we store that choice in a variable. Later, the script displays that stored value inside dialogue.
Step 1 - Create a variable
string drink;
Step 2 - Create the script
A later text line will reference the stored value.
[main]
What drink do you prefer?
coffee -> Coffee
tea -> Tea
[coffee]
t:final=Nice choice! Coffee is energizing.
[tea]
t:final=Tea is calming and gentle.
[final]
Later that day...
You take a sip of your {drink}.
Note: is just a placeholder string. You can choose any format you prefer - we will replace it in the event handler.
Step 3 - Handle the value in an event
We use the beginHandleScene event to detect which scene was reached and set or replace text accordingly.
We use the loadedGameScripts event to reset the variable value so it always clears correctly during new gameplays.
override void loadedGameScripts(SceneEntry[string] scenes, SaveFile saveFile)
{
drink = "";
}
override void beginHandleScene(ref SceneEntry scene, ref SceneEntry nextScene, bool isEnding, SceneEntry[string] scenes)
{
if (scene.name == "coffee")
drink = "coffee";
else if (scene.name == "tea")
drink = "tea";
else if (scene.original == "final")
{
scene.text = scene.text.replace("{drink}", drink);
}
}
Result
Depending on the player's earlier choice, the final line will read:
You take a sip of your coffee.
or
You take a sip of your tea.
Conditional Dialogue
In this example, we create a choice that affects later dialogue based on whether the player picked up an item. Unlike the previous example, here the text changes based on a condition.
Step 1 - Create a variable
bool hasKey;
Step 2 - Create the script
Later dialogue will change depending on the stored value.
[main]
Do you pick up the key?
pick-up-key -> Yes.
leave-the-key -> No.
[pick-up-key]
t:final=You pick up the key.
[leave-the-key]
t:final=You leave the key be.
[final]
You walk in front of a locked door.
{result}
is just a placeholder. We will replace it in the event handler.
Step 3 - Handle the condition in an event
We use the beginHandleScene event to detect which scene is reached and set the variable accordingly.
We also override loadedGameScripts to reset the variable when loading (so previous playthroughs don't leak state).
override void loadedGameScripts(SceneEntry[string] scenes, SaveFile saveFile)
{
hasKey = false;
}
override void beginHandleScene(ref SceneEntry scene, ref SceneEntry nextScene, bool isEnding, SceneEntry[string] scenes)
{
if (scene.name == "pick-up-key")
hasKey = true;
else if (scene.original == "final")
{
if (scene.text == "{result}")
{
if (hasKey) scene.text = "You open the door.";
else scene.text = "You can't open the door.";
}
}
}
Result
Depending on the player's earlier choice, the final line will display:
You open the door.
or
You can't open the door.
Tip: Try adding more logic or different outcomes to expand the system.
Save/Load Tutorial
In this example, we expand the Conditional Dialogue system so the player's choice persists across save and load.
We will store the hasKey variable in the save file and restore it when loading.
Step 1 - Load the value from the save
Inside loadedGameScripts we check whether the save contains our variable.
If it exists, we restore it. If not, we fall back to a default value.
override void loadedGameScripts(SceneEntry[string] scenes, SaveFile saveFile)
{
import std.conv : to;
if (saveFile && "hasKey" in saveFile.meta)
hasKey = saveFile.meta["hasKey"].to!bool;
else
hasKey = false;
}
Step 2 - Save the value when the game is saved
We now store the current value of hasKey into the save file's metadata.
override void savingGame(SaveFile[string] saves, SaveFile saveFile)
{
import std.conv : to;
saveFile.meta["hasKey"] = hasKey.to!string;
}
Result
After adding this, the game will:
- Remember whether the player picked up the key
- Restore the correct conditional dialogue when the save is loaded
- Persist the choice across multiple sessions automatically
The rest of the script does not need any changes.
Custom Character Expressions
In this example we're going to look at changing character expressions.
In DVN each expression is a separate character entry.
Step 1 - Define your expressions in characters.json
{
"Yvonne": {
"default": "Neutral",
"Neutral": "data/game/characters/Yvonne/neutral.png",
"Sad": "data/game/characters/Yvonne/sad.png",
"Happy": "data/game/characters/Yvonne/happy.png"
}
}
Note: Expression names are just labels. You can organize expressions however you want - by emotion, pose, outfit, or metadata.
Step 2 - Reference the expressions in script
[main]
c=Yvonne,Neutral
Do you leave Yvonne alone?
leave-yvonne-alone -> Yes.
stay-with-yvonne -> No.
[leave-yvonne-alone]
c=Yvonne,Sad
Yvonne=Why are you leaving me?
[stay-with-yvonne]
c=Yvonne,Happy
Yvonne=I'm glad you're staying.
Result
Depending on the player's choice, Yvonne's expression will change:
Yvonne,Sad -> displayed if player chooses to leave
Yvonne,Happy -> displayed if player chooses to stay
Effects Chain Example
In this example, we apply more than one effect at the same time.
DVN supports effect stacking, which means multiple visual effects or transitions can run together.
This allows cinematic moments, dramatic reactions, and layered motion.
[main]
bg=Background
c=Character
# Apply multiple effects
effect=BackgroundMoveZoom
effect=ScreenShake
This scene is pure madness!!
Result
Both effects trigger together:
- The background zooms and moves.
- The screen shakes.
- The text displays while the effects are active.
Effects remain active for their defined duration or until another effect cancels or overrides them.
Simple Animation/Movement
In this example, we'll slide a character onto the screen.
DVN allows simple movement such as sliding a sprite from outside the screen into a visible position.
Step 1 - Move the character
Use the charMovement command (or shorthand cm) to move the currently active character.
cm=left
This will position the character off-screen on the left and begin sliding them into view.
Step 2 - Adjust movement speed (optional)
You can set how fast the character moves using charMovementSpeed (or shorthand cms):
cms=42
Example Script
[main]
c=Alice
cm=left
cms=42
Alice=I'm here!
Result
Alice will slide onto the screen from the left at the defined speed. Movement happens gradually over multiple frames, creating smooth motion.
Tip: Try changing cm=right or lowering the speed to cms=10 to compare the movement.
Timed Narrative Events
The delay command allows you to pause at the start of a scene before any UI, text or characters appear.
This is useful for:
- letting a background “breathe” before dialogue
- adding suspense before a line
- slow, cinematic scene entrances
Example
[main]
bg=DarkRoom
delay=1500
c=Alice
...
Is someone there?
What Happens
When this scene starts:
- The background DarkRoom is shown.
- DVN waits 1500 ms (1.5 seconds) with no UI or text visible.
- After the delay, the UI appears and the script continues:
- Alice is set as the active character
- text starts rendering as usual
Using Delay With Effects
If you want an effect to run during the delayed cinematic moment, use effect:pre.
This ensures the effect happens before the UI and text appear - not afterward.
[scary-moment]
bg=Hallway
effect:pre=ScreenShake
delay=2000
You feel something watching you.
Result
- The hallway background appears.
- The screen shakes during the silent delay.
- After 2 seconds, the UI fades in and text appears:
You feel something watching you.
Notes
- delay runs once when the scene starts.
- effect also runs after delay unless written as effect:pre.
- Use delays sparingly - too many pauses can frustrate player
- Best used for horror, emotional beats, dream sequences, or dramatic impact.
Basic UI Modification
In this example, we reposition the dialogue panel so it appears at the top of the screen instead of the bottom.
Step 1 - Override the Dialogue Panel Render Event
UI elements in DVN are controlled at runtime, so to modify layout we override the event:
override void renderGameViewDialoguePanel(Panel panel)
{
// Modify the panel here
}
Step 2 - Move the Panel
Inside the event, we assign a new screen position. Coordinates are in pixels.
override void renderGameViewDialoguePanel(Panel panel)
{
panel.position = IntVector(
panel.x, // Keep the current X position
16 // Move the panel to the top with a 16px margin
);
}
Result
The dialogue panel will now appear at the top of the screen with a 16-pixel offset. All dialogue will render inside the repositioned panel.
Optional
Try changing the values to experiment with different layouts, for example:
panel.position = IntVector(50, 300);
Importing JSON or CSV
Sometimes you may want to load external data into your game - for example lists, names, items, dialogue entries, or world data.
In this example, we will load a list of fruits from a JSON file and display it in the story.
Step 1 - Create a JSON file
Create a file named fruits.json:
[
"apples",
"bananas",
"oranges"
]
Make sure this file exists in your game's folder (the path you load must match exactly).
Step 2 - Create a variable to store the data
string[] fruits;
Step 3 - Load the file when the engine is ready
We use the engineReady event to read the file before gameplay begins.
override void engineReady(Application app, Window[] windows)
{
import std.file : readText;
auto text = readText("fruits.json");
string[] errorMessages;
if (!deserializeJsonSafe!(string[])(text, fruits, errorMessages))
{
throw new Exception(errorMessages[0]);
}
}
Step 4 - Use the placeholder in the script
[shop]
Alice=Can I buy some fruits?
Shopkeeper=Yes, we have the following fruits: {fruits}.
Step 5 - Replace the placeholder at runtime
override void beginHandleScene(ref SceneEntry scene, ref SceneEntry nextScene, bool isEnding, SceneEntry[string] scenes)
{
if (scene.original == "shop")
{
import std.array : join;
scene.text = scene.text.replace("{fruits}", fruits.join(", "));
}
}
Result
Yes, we have the following fruits: apples, bananas, oranges.
Notes
You can store any kind of structured data in external files: inventory, dialogue, shop lists, NPC names, etc.
CSV works similarly - parse it and assign the values to variables before use.
Randomized Narrative Events
DVN supports simple chance-based branching using the chance command. This lets you introduce surprises, rare lines, secret events, or variation in repeated playthroughs.
The chance command works by giving the next text line (or option) a probability of appearing.
Example
[main]
chance=10
This is some secret text.
Hello, world!
Result
- There is a 10% chance the first line will appear.
- If it does not trigger, DVN automatically skips it.
- The second line always appears.
So sometimes the scene will output:
This is some secret text.
Hello, world
...and other times:
Hello, world!
Notes
- chance applies only to the next line or next choice option.
- You can use multiple chance commands in one scene for layered random behavior.
- Randomness is seeded, which means if randomness is tied to save states, it will behave consistently on restore.
Optional Variation: Randomized Options
[main]
What happens next?
chance=30
rare -> Something unusual...
normal -> Nothing special happens.
This gives one of the options a 30% chance of appearing.
Advanced (Power Users)
This section is for users who already know their way around DVN's scripting, events, custom views, and core API - and are ready to go beyond standard VN structure.
State-Based Story Navigation
DVN allows scenes to advance based on stored values rather than fixed script jumps. This means the story can react dynamically to player decisions, items, or previous choices.
This behavior is implemented using the beginHandleScene event.
Example Scenario
The player reaches a locked door.
If they found the key earlier, the story automatically branches to the "open-door" scene instead of the normal locked-door dialogue.
bool hasKey; // This could be set elsewhere when the player picks up the key
override void beginHandleScene(
ref SceneEntry scene,
ref SceneEntry nextScene,
bool isEnding,
SceneEntry[string] scenes)
{
// Check if the player is at the locked door scene
if (scene.name == "in-front-of-door")
{
// If the player has the key, redirect the story
if (hasKey)
{
scene = scenes.get("open-door", null);
nextScene = _scenes.get(scene.nextScene, null);
}
}
}
hat This Achieves
- No special script syntax needed
- The story updates dynamically based on player state
- Multiple playthrough paths become possible without restructuring scene files
- Logic stays cleanly separated from narrative content
This approach is ideal for:
- Persistent world decisions
- Variable-driven branches
- RPG/VN hybrid logic
- Inventory-based progression
- Consequence systems (trust level, dating sim affinity, flags, etc.)
Instead of thinking in terms of "go to scene X", this pattern lets you think in terms of "the story continues based on what the player has done."
Minigame / Interaction (Custom Gameplay)
DVN allows you to extend your visual novel with custom interaction logic, mini-games, or gameplay segments. In this example, we create a simple Rock, Scissor, Paper minigame where the player makes a choice, and the result determines which scene plays next.
If the player:
- wins -> go to the win scene
- loses -> go to the lose scene (with the option to try again)
- draws -> go to the draw scene (also retryable)
Step 1 - Script Setup
We define the scenes that connect the story to the minigame logic:
[main]
Alice=Do you want to play rock, scissor, paper?
Bob:play-rock-scissor-paper=Absolutely!
[play-rock-scissor-paper]
view=RockScissorPaperView
[win]
Alice=Aw, I didn't expect you'd win!
[lose]
Alice=You lose! You can try your luck again!
Bob:play-rock-scissor-paper=Sure.
[draw]
Alice=It is a draw, you can try your luck again!
Bob:play-rock-scissor-paper=Okay.
Notice the line:
view=RockScissorPaperView
This tells DVN to switch from scripted dialogue to a custom interactive view.
Step 2 - Creating the Custom View
We now implement the UI and gameplay logic.
public final class RockScissorPaperView : View
{
public:
final:
this(Window window)
{
super(window);
}
protected override void onInitialize(bool useCache)
{
EXT_DisableKeyboardState();
auto window = super.window;
auto settings = getGlobalSettings();
auto label = new Label(window);
addComponent(label);
label.fontName = settings.defaultFont;
label.fontSize = 24;
label.color = "fff".getColorByHex;
label.text = "What do you pick?";
label.shadow = true;
label.anchor = Anchor.top;
label.updateRect();
label.show();
void pick(string value)
{
import std.random : uniform;
string alicePicked;
auto result = uniform(0, 100);
if (result > 66) alicePicked = "rock";
else if (result > 33) alicePicked = "scissor";
else alicePicked = "paper";
string scene;
if (value == "rock")
{
if (alicePicked == "scissor") scene = "win";
else if (alicePicked == "paper") scene = "lose";
else scene = "draw";
}
else if (value == "scissor")
{
if (alicePicked == "paper") scene = "win";
else if (alicePicked == "rock") scene = "lose";
else scene = "draw";
}
else // if (value == "paper")
{
if (alicePicked == "rock") scene = "win";
else if (alicePicked == "scissor") scene = "lose";
else scene = "draw";
}
displayScene(scene);
}
auto rock = new Button(window);
addComponent(rock);
rock.fontName = settings.defaultFont;
rock.fontSize = 32;
rock.text = "Rock";
rock.size = IntVector(window.width / 2, 64);
rock.moveBelow(label, 16, true);
rock.show();
rock.onButtonClick(new MouseButtonEventHandler((b,p)
{
pick("rock");
}));
auto scissor = new Button(window);
addComponent(scissor);
scissor.fontName = settings.defaultFont;
scissor.fontSize = 32;
scissor.text = "Scissor";
scissor.size = IntVector(window.width / 2, 64);
scissor.moveBelow(rock, 16, true);
scissor.show();
scissor.onButtonClick(new MouseButtonEventHandler((b,p)
{
pick("scissor");
}));
auto paper = new Button(window);
addComponent(paper);
paper.fontName = settings.defaultFont;
paper.fontSize = 32;
paper.text = "Paper";
paper.size = IntVector(window.width / 2, 64);
paper.moveBelow(scissor, 16, true);
paper.show();
paper.onButtonClick(new MouseButtonEventHandler((b,p)
{
pick("paper");
}));
}
}
...
public override void loadingViews(Window window)
{
window.addView!RockScissorPaperView("RockScissorPaperView");
}
Notice the line:
displayScene(scene);
This tells DVN to go to the scene specified.
Summary
This example demonstrates how DVN can:
- pause normal script flow
- run interactive custom logic
- and return to narrative scenes based on user input or game state
This approach can be adapted for:
- puzzles
- quick-time events
- stat-based interaction
- mini-games
- visual menus
- choice wheels
- or full gameplay systems
Inventory System
An inventory system allows the player to collect items and use them later in the story. Unlike simple branching, an inventory is persistent and can affect multiple scenes across the narrative.
In this example, the player finds a rusty key. If they pick it up, the key is stored in memory and later used to unlock a door. If they ignore it, the story branches differently and the door remains locked.
This demonstrates three core concepts:
- Storing item data
- Displaying items in a custom UI
- Using stored items to influence scene progression
Step 1 - Script Setup
The script defines a simple flow where the player may pick up an item, and later attempt to unlock a door:
[main]
Alice=There is an old rusty key here. Should we pick it up?
pickup -> Pick it up
leave -> Leave it
[pickup]
Alice:room=Got it.
[leave]
Alice:room=Okay... maybe later.
[room]
Alice:show-inventory=The door is locked.
[show-inventory]
view=InventoryView
[door-open]
Alice=The key worked!
Step 2 - Inventory Storyage
We store collected items in a simple associative array.
This keeps the system flexible and easy to extend later.
bool[string] inventory;
Step 3 - Responding to Game State
Using the beginHandleScene event, we detect when the player picks up an item and modify future scene behavior based on inventory content.
override void beginHandleScene(
ref SceneEntry scene,
ref SceneEntry nextScene,
bool isEnding,
SceneEntry[string] scenes)
{
if (scene.original == "pickup")
{
inventory["rusty-key"] = true;
}
else if (scene.original == "room")
{
if (!("rusty-key" in inventory))
{
nextScene = null;
}
}
}
- When the player reaches the pickup scene, the key is added.
- When they reach the room, DVN checks whether the key exists and blocks progression if it does not.
Step 4 - Inventory UI
The InventoryView allows the player to interact with collected items.
Clicking an item triggers logic that determines the next scene.
public final class InventoryView : View
{
public:
final:
this(Window window)
{
super(window);
}
protected override void onInitialize(bool useCache)
{
EXT_DisableKeyboardState();
auto window = super.window;
auto settings = getGlobalSettings();
auto label = new Label(window);
addComponent(label);
label.fontName = settings.defaultFont;
label.fontSize = 24;
label.color = "fff".getColorByHex;
label.text = "What item do you want to use?";
label.shadow = true;
label.anchor = Anchor.top;
label.updateRect();
label.show();
Label lastLabel = label;
foreach (item,v; inventory)
{
import std.conv : to;
auto itemLabel = new Label(window);
addComponent(itemLabel);
itemLabel.fontName = settings.defaultFont;
itemLabel.fontSize = 24;
itemLabel.color = "fff".getColorByHex;
itemLabel.text = item.to!dstring;
itemLabel.shadow = true;
itemLabel.moveBelow(lastLabel, 16, true);
itemLabel.updateRect();
itemLabel.show();
lastLabel = itemLabel;
// We need to make a closure else the foreach loop swallows our label and item
auto closure = (Label l, string itemName) { return () {
l.onMouseButtonUp(new MouseButtonEventHandler((b,p) {
switch (itemName)
{
case "rusty-key":
displayScene("door-open");
break;
default: break;
}
}));
};};
closure(itemLabel, item)();
}
}
}
Step 5 - Register the View
public override void loadingViews(Window window)
{
window.addView!InventoryView("InventoryView");
}
Summary
This example shows how an item collected earlier in the narrative can:
- persist across scenes
- be displayed visually
- and be used later to unlock new story routes
Inventory systems like this can be expanded to support:
- quantities
- item descriptions
- tooltips
- categories
- consumables
- drag-and-drop
- or crafting logic
This makes DVN suitable for VN/RPG hybrids, puzzle-driven storytelling, or narrative games with progression mechanics.