Applied The Lora Playbook

Dialogue, Objectives, and Save States

Last reviewed

Intermediate

What you'll learn

~60 min
  • Build a JSON-driven branching dialogue system with NPC portraits and choice buttons
  • Implement an objective tracker with sidebar checklist and completion state
  • Create a localStorage save/load system with chapter select
  • Generate dialogue tree JSON files by describing conversations in plain English

What you’re building

Your prototype has combat, movement, a HUD, and an inventory. A player can fight enemies, collect items, and manage resources. What they cannot do is understand why they are fighting, what they are supposed to accomplish, or pick up where they left off after closing the browser. The game has mechanics but no context.

BloodRayne was an objective-driven game. Each level started with a mission briefing — infiltrate the Nazi compound, destroy the research lab, eliminate the target. NPCs gave you intel and sometimes offered choices. The game saved at checkpoints so dying did not mean starting over from scratch. These are not luxury features. They are the difference between “I’m mashing buttons in a test room” and “I’m a vampire agent on a mission.”

Forty-five minutes from now you will have a branching dialogue system driven by JSON files (so you can generate new conversations by describing them in plain English), an objective tracker that shows a sidebar checklist with live completion status, and a localStorage save/load system that lets the player resume from any chapter they have reached.

ℹSoftware pattern: Data-driven narrative engine

JSON dialogue trees + state machine for conversation flow + persistent storage for progress. This pattern is used in visual novels, RPGs, interactive fiction, chatbot flows, onboarding wizards, and any application where users navigate branching paths with persistent state.


The showcase

Here is the complete system you end up with:

  • Dialogue box: Bottom of screen, dark panel with NPC portrait (colored rectangle placeholder), NPC name, dialogue text that types out letter-by-letter, and up to 3 choice buttons when branching occurs.
  • Branching conversations: Dialogue trees stored as JSON. Each node has text, an optional speaker portrait, and optional choices that branch to different nodes. The AI generates these files — you describe the conversation, it writes the JSON.
  • Objective tracker: Right sidebar, semi-transparent panel listing current objectives as a checklist. Completed objectives get a checkmark and strikethrough. New objectives added dynamically as dialogue triggers them.
  • Save/load system: Auto-saves to localStorage on chapter transitions and objective completions. Manual save with a “Save” button in the pause screen. Load screen shows available saves with chapter name, timestamp, and completion percentage.
  • Chapter select: From the title/load screen, choose any chapter the player has previously reached. Each chapter restores the player’s state (health, inventory, objectives) from the save data.

Before you start

If your AI tool is open from the last lesson, leave it (/exit, or Ctrl+D in Antigravity) so you are back at your terminal prompt. Create a folder for this lesson and step into it:

Terminal window
mkdir -p ~/retro-remake/16-dialogue-objectives-save && cd ~/retro-remake/16-dialogue-objectives-save

In Windows PowerShell, run mkdir ~/retro-remake/16-dialogue-objectives-save; cd ~/retro-remake/16-dialogue-objectives-save. In a desktop agent app, open ~/retro-remake/16-dialogue-objectives-save as your workspace folder. Then start your AI tool the way Workbench Setup showed.

Switch to plan mode

Switch into Plan mode (Shift+Tab, /plan, or the mode picker) so your agent aligns on the JSON dialogue schema, objective checklist, and localStorage save slots before writing code.

The conversation

Each message below is an example. Say it in your own words.

Say what you want

Ask for a browser-based dialogue, objective tracker, and save/load system driven by data files:

Build a browser-based branching dialogue system, sidebar objective tracker, and save/load system driven by separate JSON data files so I can add conversations easily. Ask me what you need first.

Answer its questions

Your agent will ask about the dialogue data structure, how objectives activate and complete, how saves and chapters work, and the gameplay test room:

If it asksYou might say
What should each dialogue node include?Speaker name, portrait color, typewriter text, 1-to-3 branching choices, and optional objective or auto-save triggers.
Which starter dialogue and objective files should we include?Chapter 1 commander briefing (stealth vs assault choice), an NPC ally conversation, and a Chapter 1 objectives list.
How should the objective tracker overlay work?A right-hand checklist toggled with Tab showing required and optional objectives, checkmarks, and a completion banner.
What should the title screen and save system support?New Game, Load Game (3 browser save slots with timestamp and completion %), and Chapter Select.
How do I test everything in the gameplay scene?WASD movement, two NPCs with E to talk prompts, collectible objective triggers, and an exit zone.

Read the plan

Before approving the build, check the agent’s plan for these four details:

  1. JSON-driven dialogue (src/DialogueScene.js + public/data/*.json): fetches /data/chapter1-briefing.json and /data/chapter1-npc-ally.json from public/data/, renders an 80x80 speaker portrait block and letter-by-letter typewriter text (30ms/char, Space/click to finish or advance), supports mouse or keys 1-3 for choices, and executes setObjective and triggerSave actions on nodes.
  2. Dynamic objective sidebar (src/ObjectiveScene.js): loads /data/chapter1-objectives.json, activates infiltrate_east or assault_front based on the player’s briefing choice, marks optional objectives with (optional), toggles visibility with TAB, and flashes "ALL OBJECTIVES COMPLETE" when required items are done.
  3. Three-slot save manager (src/SaveManager.js): stores { chapter, objectives, inventory, health, rage, enemiesDefeated, timestamp, playTimeSeconds } under lorastudio-save-{slot} in localStorage, supporting auto-save on dialogue/objective milestones and manual save from the pause menu.
  4. Title screen with Load and Chapter Select (src/TitleScene.js): offers NEW GAME, LOAD GAME (displaying slot chapter, timestamp, and completion percentage), and CHAPTER SELECT (unlocking chapters up to highest completed + 1).

If the plan puts the JSON files inside src/ instead of public/data/ or forgets node-level objective triggers, steer it before approving:

Keep the dialogue and objective JSON files in a separate data folder loaded at runtime, and let dialogue choices activate objectives and trigger an auto-save.

Once the plan covers all four points, approve it and let your agent build the project. After testing a branching conversation, saving, refreshing, and loading in your browser, ask your agent to save a Git checkpoint.

💡The JSON format is the real power

The dialogue tree is just data. That means you can generate new conversations by describing them in plain English to your AI tool. Ask for a dialogue tree JSON where an NPC warns Rayne about a trap with two choices, drop it into public/data/, and the engine plays it without code changes.


What you get

After generation, the project folder structure looks like this:

16-dialogue-objectives-save/
package.json
index.html
src/
main.js
TitleScene.js
GameScene.js
DialogueScene.js
ObjectiveScene.js
SaveManager.js
state.js
public/data/
chapter1-briefing.json
chapter1-npc-ally.json
chapter1-objectives.json

Fire it up

Ask your agent to install what is needed, start the local server, and open the game:

Install the packages, start the local server, and open the dialogue and objectives prototype in my browser.

Or run it from a terminal:

Terminal window
cd ~/retro-remake/16-dialogue-objectives-save
npm install
npm run dev

Open the URL. You should see the title screen with “NEW GAME” and “LOAD GAME” buttons. Click New Game. Walk the purple player square toward the blue NPC with the ”!” marker. When you see “E to talk,” press E. The dialogue box should slide in at the bottom of the screen with Commander Wulf’s briefing text typing out letter by letter.

Make a choice when the branching options appear. Watch the objective tracker on the right side update with your new objective. Walk over the objective items to complete them. Press ESC to pause and save, or let the auto-save trigger at chapter transitions.

If something is off

ProblemFollow-up prompt
Dialogue JSON fails to loadWhen I press E to talk to an NPC, the conversation fails to load. Make sure the dialogue and objective JSON files sit in the public data folder and load cleanly when the scene starts.
Text typewriter effect is instantThe dialogue line appears all at once instead of typing out letter by letter. Reveal one character every 30 milliseconds, and let pressing Space or clicking finish the current line immediately before advancing.
Choice buttons are not clickableThe branching choice buttons appear on screen, but clicking them does nothing. Make each choice button clickable and also selectable with number keys 1 to 3 so choosing an option advances the conversation.
Save data does not persistAfter I save the game and refresh the browser, Load Game shows empty slots. Make sure the save slots write to and read from persistent browser storage using matching slot keys.

Deep dive

Three systems are working together here, and the architecture is what matters.

JSON-driven dialogue is the key design decision. The dialogue engine does not contain any conversation content. It reads JSON files that describe who says what, what choices exist, and what happens when the player picks one. This means the AI CLI becomes your dialogue writer. You describe a conversation in plain English, it generates the JSON, and the engine plays it. No code changes. No recompilation. Just data.

The objective system is a checklist with triggers. Each objective has an ID. Dialogue nodes can activate objectives (the setObjective field). Game events can complete objectives (walking over a trigger zone). The objective scene reads the list and renders checkboxes. This is the same pattern as a task management system — items have states, transitions happen based on events, and the UI reflects current state.

localStorage is your save file. Browsers give each site (origin) about 5 MiB of localStorage. A save file for this game is maybe 2 KB, so you could store hundreds of saves and never come close to the limit. The SaveManager serializes the entire game state to JSON and stores it under a key. Loading deserializes it back.

🔍Generating new dialogue with AI promptsclick to expand

Here is the real workflow once this system is running. You want a new NPC conversation. Ask your AI tool:

Write a dialogue JSON matching chapter1-briefing.json where a captured scientist offers Rayne a keycard if freed, with a choice to trust him (sets use_keycard) or refuse (sets find_alternate_route).

The AI generates the JSON. You save it as chapter1-scientist.json in public/data/. You add a new NPC to the scene that triggers this dialogue file. No code changes to the dialogue engine. The content scales independently of the system. That separation is the whole point.


Customize it

Add dialogue portraits with expressions

Add an optional expression setting (neutral, angry, surprised, sad) to dialogue nodes that adjusts the speaker portrait's color intensity and overlays a simple expression marker like ! or ?.

Add a quest log

Add a Quest Log view to the pause screen grouping objectives by chapter into active, completed (with timestamp), and failed states, pulling descriptions from the objectives data.

Add dialogue history

Add a scrollable dialogue history log on the pause screen that records every line seen and highlights the player's chosen responses, persisted inside the save slot data.

Try it yourself

  1. Walk through the plan-mode conversation above and let your agent build the project.
  2. Ask your agent to start the app (or run npm install && npm run dev) and start a new game.
  3. Walk to the first NPC and trigger the briefing dialogue. Read through the conversation and make a choice at the branching point.
  4. Check the objective tracker — your choice should have activated the corresponding objective.
  5. Complete some objectives by walking over trigger items. Watch the checklist update.
  6. Press ESC, save the game. Refresh the browser. Load your save. Verify your progress was preserved.
  7. Write a new dialogue JSON by hand or by prompting your AI CLI. Add a new NPC in GameScene that triggers it. Test the new conversation without changing any engine code.

Key takeaways

  • Data-driven dialogue means the engine and the content are separate. New conversations are JSON files, not code changes. The AI CLI generates the data, the engine plays it.
  • Branching choices create replay value and player agency. The same BloodRayne mission plays differently depending on whether you chose stealth or assault.
  • Objective tracking turns an open sandbox into a directed experience. Players know what to do, and the checklist provides constant feedback on progress.
  • localStorage saves are simple, reliable, and free. No backend, no accounts, no server costs. The player’s progress persists across browser sessions.
  • Chapter select from saves respects the player’s time. Nobody wants to replay 30 minutes of content they already completed because they closed a browser tab.
💡The dialogue system is your narrative backbone

Every story-driven game needs a way to deliver exposition, present choices, and track consequences. This JSON-driven approach means you can prototype an entire game’s worth of narrative content in an afternoon using AI prompts, without touching the engine code. Write the story, generate the JSON, drop it in public/data/. That is the workflow.


What’s next

You have mechanics, UI, narrative, and persistence. The one thing you cannot do yet is design levels efficiently. In the next lesson you will build a browser-based level editor — a tile placement tool where you click to place ground, walls, platforms, hazards, spawns, and exits on a grid, then export the layout as JSON that Phaser can load directly. That is the tool that turns level design from “manually typing coordinates” into “click where you want things.”

intellimetrics · Arlington, VA
© 2026 intellimetrics.net
Search lessons