How to Write a Branching Visual Novel with Choices and Variables
Plan a branching visual novel: scenes, choices, variables and conditions, a flowchart to catch dead ends, then a play test and export to HTML or Ren'Py.

How to Write a Branching Visual Novel with Choices and Variables
A visual novel is a story told through backgrounds, character portraits and lines of dialogue, where the reader makes choices that change what happens next. The hard part is rarely the writing. It is keeping track of the branches: which scene leads where, which choice depends on an earlier decision and whether every path actually reaches an ending. This guide explains how branching stories are built and shows the process in the free visual novel builder.
Scenes are the building blocks
Think of a scene as one location and one moment, such as "Train station, evening". Each scene has a background, which can be a colour, a CSS gradient or an image, and a list of lines played in order. A line is one of three things:
- Narration, text with no speaker.
- Character dialogue, with a speaker, an expression sprite (for example "smile" or "angry") and a position on screen: left, centre or right.
- Set variable, which silently adds to, subtracts from or sets a number.
When the lines run out, the scene either offers choices, moves on to a fixed next scene or ends the story.
Characters
Each character has a name colour, so readers can tell speakers apart at a glance, and a sprite for each expression. Keeping expressions as named sprites means you write "Mara, worried, left" instead of hunting for file names every time.
Variables turn choices into consequences
Without variables, a branching story is just a maze. With them, small decisions can add up. A common pattern is a relationship score. If the reader comforts Mara, a line adds 1 to trust; if they meet her brother, another line sets met to 1. Later, a choice can carry a condition such as trust >= 2 and met == 1, and only appears when both are true.
Variables can also appear in text. Writing You have {trust} reasons to stay shows the current value, which is useful for debugging and for stories that track money or days.
Map the story with the flowchart
The flowchart draws every scene as a node and every link as an arrow. Conditional choices use dashed arrows, so you can see at once which routes are locked behind earlier decisions. You can drag nodes around or let the tidy layout arrange them.
More useful than the picture are the checks. The builder warns about:
- Unreachable scenes that no path leads to.
- Dead ends, scenes with no choices, no next scene and no ending.
- Broken links to scenes that were renamed or deleted.
- Unreadable conditions with a typo the player could never satisfy.
- Undeclared variables used in a condition but never set.
It also counts how many distinct paths reach each ending, which tells you whether one ending is easy to find and another almost hidden.
A worked example
Take a short story with six scenes and two endings. In scene 2 the reader can comfort Mara (+1 trust) or ignore her (0). In scene 3 they can help her again (+1 trust) and in scene 4 they may meet her brother (met = 1). Scene 5 offers "Ask her to come with you" only if trust >= 2 and met == 1; otherwise only "Leave alone" is shown.
With two options in each of the three earlier choices, there are 2 × 2 × 2 = 8 routes into scene 5. Only one of them meets the condition, because trust reaches 2 only when the reader comforts and helps her, and met is 1 only when they meet the brother. The path counter would show 1 path to the "together" ending and 7 to "alone". If that feels too strict, change the condition to trust >= 1 and the count shifts to 3 and 5.
Play test and export
The built-in play test uses the same player as the export, so what you see is what readers get. You can export:
- One offline HTML file with the full player: save slots, a history log of past lines, auto mode and adjustable text speed. Anyone can open it without installing anything.
- A Ren'Py .rpy script skeleton with scenes, labels, menus and variables, as a starting point if you move to Ren'Py.
- Story JSON for backups or your own engine.
Everything is edited and stored in the browser, so your story stays on your device.
Limits
The builder does not handle music or sound effects, and animation is limited to basic transitions. Images are stored in browser storage, which holds roughly 5 MB, so large or many backgrounds may not fit; compress them first. The Ren'Py export is a script skeleton only and does not include images, so you need to add the art files in your Ren'Py project yourself.



