Dialogue scripts (.vn)
Write a scene as plain text. events/town/sign/index.vn becomes the event 'town/sign', just like an index.ts would. So does the single file events/town/sign.vn.
An example
# The town sign. Lines starting with # are comments.
title The town sign
> An old wooden sign. Someone carved a message into it.
> {i}"Welcome to town. Be kind to the slimes."{/i}
if flag('read_sign'):
> You have read it before. It hasn't changed.
else:
set read_sign = true
> Behind the sign, half buried, something glints.
choice:
* Dig it up
give apple
money +5
> An apple and a few coins. Lucky!
* Leave it
> You leave it where it is.
A file in src/content/routes/ is a route script instead (the story's order in visual novel mode): see Routes & flowchart.
Every file needs one title line (not indented, usually at the top): the event's name on saves made during it, like a map's title.
Blocks are made by indenting (spaces): the options of a choice:, and the body of if / elif / else. Blank lines don't matter.
One file per scene
A scene does not need a folder of its own. Any <name>.vn file in src/content/events/ or one of its group folders is an event, named by its path:
src/content/events/
common/day1_morning.vn # the event 'common/day1_morning'
common/day1_lunch.vn # 'common/day1_lunch'
common/day1_evening/index.vn # 'common/day1_evening' (a folder, e.g. to keep its pictures with it)
common/_notes.vn # ignored (starts with _)
- The generated file sits next to it (
day1_morning.gen.ts). - Voice files, saves and read lines go by the event id, so a scene can move between the two forms freely. When you turn a folder into a file, delete the folder (a folder and a file with the same name: the folder wins, with a warning).
- Only .vn scenes can be single files; a scene written in TypeScript keeps its folder with
index.ts.
How it works
- The file is compiled to
index.gen.tsnext to it: on save while the dev server runs, and bypnpm gen/pnpm typecheck. Don't edit the generated file. - The generated code is ordinary TypeScript, so wrong ids are type errors in
pnpm typecheck. Every generated line has a comment with its.vnline number. - Mistakes are also printed by the dev server, e.g.
[vn] events/town/sign/index.vn:12:6: unknown item "aple" (did you mean "apple"?). - A folder with both
index.tsandindex.vnuses theindex.ts. - Translations:
pnpm langreads.vnfiles too (lines, options, narration).
Lines
| Write | Does |
|---|---|
anna: Hello! | Anna says it |
anna:happy: Hello! | …and switches to her happy pose (shows her if needed) |
anna(italic, speed 0.5): Hello! | …with line options in round brackets, before the colon |
jack & anna:happy: Bye! | Said together: name tag "Jack & Anna", the plain chat box, nobody of them dimmed. Voices: jack & anna(3, 7): Bye! (one number per speaker, in name order). See Several voices |
"Student A": Hello! | A speaker who is no character: the name in quotes is shown as written (and can be translated). No portrait, no folder needed |
>(italic) Text | Narration with line options (no space between > and the bracket) |
> Text | Narration |
# comment | Ignored |
$ any TypeScript | One line of code, e.g. $ await game.maps.npc('jack').play('wave') |
Line options
Separate them with commas: anna:happy(12, as ???): Guess who.
| Option | Does |
|---|---|
as ??? · as "Anna, the baker" | Shows another name for this line (quotes when it has a comma) |
italic · shake | Slanted / shaking text |
size small · size large · color #ffcc00 | Text size and colour |
speed 0.5 | Typing speed (2 = twice as fast) |
auto 800 | Continues by itself 800 ms after the text is shown |
nopause | No short pause after . ! ? while typing |
jack 3 · jack town/x/jack_0001 | Another voice too, from someone who is not the shown speaker: anna(7, jack 3): Hm. (both clips start together) |
12 · 0012 · voice town/arrival/anna_0003 | The line's voice number (its file: audio/voice/<language>/<event id>/anna_0012.*) / a clip of another event. No number = no voice. See Voices |
face happy | The pose of the side image for this line |
thought (any other word) | A named line style from lineStyles in src/content/scenes.ts: hero(thought): I wonder.... One per line; the other options win over it |
// src/content/scenes.ts
lineStyles: {
thought: { italic: true },
whisper: { size: 'small', speed: 0.7 },
shout: { size: 'large', shake: true },
},
Put a value into a line with [ ], like Ren'Py: anna: You have [money()] coins. Inside the brackets is TypeScript (a variable from a $ line, a helper, game.…). Translators see {money}. Write [[ for a plain [.
Text supports the same markup: {b}, {i}, {color=…}, {size=…}, {shake}, {wave}, {w=0.5}.
Commands
| Command | Same as |
|---|---|
show anna at left pose happy flip | show('anna', { at: 'left', pose: 'happy', flip: true }) (all parts optional) |
show anna distance close | How near she stands: a name from stage.distances in src/content/scenes.ts |
show anna tint night · show anna tint none | A tint or filter on her only (tints) |
show anna frame 0.65 1 · frame anna 0 0.35 ms 2500 | Which part of her picture fills the stage (top to bottom, 0..1): show it at once, or animate to it (framing) |
@start · @start wave trust | Dev only: the dev server opens the game at this line (more). Builds refuse it |
hide anna / hide | Remove one / everyone |
bg street · bg town/bus_stop evening | bg(…): a background from src/content/backgrounds; one with variants (an .aseprite + index.ts) needs the variant |
bg #203040 · bg black · bg /img/sky.png · bg none | background(…): a colour (#…, rgb(…), a basic colour word), a file or URL, or none = the map |
bg #203040 with wipeLeft 800 · cg pond_memory with swirl | …through a mask transition (ms optional) |
movie /video/opening.mp4 | await movie(…): plays a video, then goes on |
image letter /img/letter.png x 50 y 40 width 30 layer top ms 500 · image letter none · image none | Pictures on stage: show or move one, take one away, take all away. Also height, opacity, scale, rotate |
weather snow 0.5 · weather none | Weather in the scene (intensity optional) |
move anna hop | A named move |
nvl on · nvl clear · nvl off | Full-page text: start, new page, back to the box |
ending true_end | Marks an ending as reached |
title The town sign | The event's title (required, once, not indented): shown on saves |
chapter town | A chapter begins here (await chapter("town"): the stage lines after it go under a covering card) |
$ const name = await input('Your name?') | Asking for text (then anna: Hi [name]!) |
cg pond_memory · cg pond_memory crying.full_moon · cg none | Gallery picture or one of its variants (and unlock it) |
inset sneaking red_girl · inset closeup ms 800 · inset none | A framed picture in the middle (src/content/insets, optional variant and fade ms) |
filter flashback · filter none | Filter preset or tint over the whole stage |
filter evening on characters · filter night on anna · filter none on background | Only one part: all, background, characters or a character (tints) |
fade #000 400 · fade none 400 | Fade to a colour / back |
wait 0.5 | Pause (seconds) |
music music/town · music none · ambient ambient/rain · sfx sfx/click | Sound |
event anna/flashback | Run another event here |
set met_anna = true · set talks += 1 · set talks -= 1 | Flags (the value is TypeScript) |
give apple 2 · take apple | Items (with a toast when given) |
money +10 · money -5 | Money |
love anna +3 | Relationship points (with a toast) |
rename god "Evil God" · reveal god | Show another name / the real name from now on (Names that change) |
xp 20 · join anna | Party XP · add to the party |
achievement builder · codex anna | Unlock |
quest start jacks_letter · quest step jacks_letter read · quest done jacks_letter | Quests |
window inventory · shop anna | Open a window / shop |
battle slime, batbattle wolf_pack | A battle (waits for it): enemies, or a troop from content/troops |
end (or return) | Stop the event here |
At the same time
Commands like fade wait until they finish. Put meanwhile in front to start one and go on at once:
meanwhile fade #ffffff51 2000
meanwhile $ await animate('god', { opacity: 1 }, { duration: 1000 })
hero: Ehh... What?
together: starts every line below it at once and goes on when all of them are done:
together:
hero: Ehh... What?
fade #ffffff51 2000
$ startShake(6)
fade #ffffff 2000
- There is one chat box, so only one line in a
together:block can be dialogue, narration, a choice or an event. - Dialogue can't be
meanwhile(it always waits for the player);wait,eventandendcan't either.endcan't be insidetogether:. - A block inside
together:(anif, achoice) counts as one line: its own lines run in order.
Choices and conditions
Condition helpers: flag('name'), has('item'), love('anna'), money(), inParty('hero'), seen('event/id') (see Run once) and variant('adult') (this build's content variant).
choice:
* Yes, please
anna: Great!
* Only friends see this if love('anna') >= 10 and not flag('met_anna')
> A secret option.
* No
if flag('met_anna'):
anna: Again?
elif has('apple', 2) or money() > 50:
anna: Rich!
else:
anna: Hi.
- An option with
if …at the end is hidden unless the condition is true. - Conditions are TypeScript with helpers and the words
and,or,not.
| Helper | |
|---|---|
flag('met_anna') | A flag's value |
has('apple'), has('apple', 3) | Carrying it |
love('anna') | Relationship points |
money() | Money |
inParty('anna') | In the party |
seen('anna/hello') | That event has started in this playthrough |
variant('adult') | This build is that content variant |
Anything else: write TypeScript, e.g. if game.clock.hour() >= 20: or $ const roll = random(). game, ctx and every scene command (say, show, animate, camera, shake, flash, random…) are available by name.
Editor extension
Kroniki VN Scripts, for VSCodium / VS Code: colouring, suggestions and red underlines while you type.
- Build it:
pnpm vn:extension→build/vn-extension/kroniki-vn-scripts-<version>.vsix. - In the editor's Extensions view: the … menu → Install from VSIX… → pick that file.
- Suggestions by context: characters and commands at the start of a line, poses after
anna:orpose, stage positions afterat, items aftergive, enemies and troops afterbattle, sounds aftermusic, flags aftersetor insideflag(', markup tags after{. - Checks as you type: unknown ids with "did you mean", lines it doesn't understand, bad indentation, a voice number one speaker already used in the file.
- Voice numbers: after
anna(the first suggestion is Anna's next free number in this file (0008); aftervoicethe recorded clips of other events. - New content works at once. The ids are read from the open project and re-read when anything in
src/contentchanges. You only rebuild/reinstall when the extension itself changes (bump the version intools/vscode-vn/package.json). - The title bar button VN: Show generated TypeScript opens the
index.gen.tsbeside it.
The rules live in vite/vn/: compile.ts (to TypeScript), check.ts (ids), complete.ts (suggestions), ids.ts (reads the project). The extension and the dev server share them.
Adding a command
- Add a
caseincommand()invite/vn/compile.ts(it returns one line of TypeScript). - If its argument is an id, add it to
COMMAND_ARGSincheck.ts; add a suggestion toCOMMANDSincomplete.ts; add the word to the grammar intools/vscode-vn/syntaxes/vn.tmLanguage.json. - Add a test in
vite/vn/*.test.ts, update this page, rebuild the extension.