Events: writing a scene
Events are visual-novel scenes: dialogue at the bottom, portraits on stage, choices, effects. They're async scripts, so a scene reads top to bottom. You can also write them as .vn text files.
A first event
// src/content/events/anna/hello/index.ts → the event 'anna/hello'
import { defineEvent } from '@/core/define'
export default defineEvent({
title: 'Talking to Anna', // like a map's title: shown on saves made during this event
run: async ({ say, narrate, choice, show, hide, game }) => {
show('anna', { at: 'right', pose: 'happy' })
await say('anna', 'Hi! What can I do for you?')
const pick = await choice({ shop: 'Do you sell anything?', bye: 'I have to go.' })
if (pick === 'shop') game.shops.open('anna')
else await narrate('She waves.', { italic: true })
hide('anna')
},
})
Want to see it all running? Read the town sign in the demo and take the tour (src/content/events/town/showcase).
Start it from anywhere: await game.events.start('anna/hello'). Usually from a map object's onInteract, a prop, an item's use, or another event.
- The map stays visible behind the scene; NPCs can walk while people talk.
- Awaiting a line waits for the player. Not awaiting an effect lets it run alongside the next line.
- When the event ends, the stage is reset (portraits, background, filters, camera). The log is kept.
Everything a script gets
| Command | |
|---|---|
say(who, text, options?) | A line. who is a character id, or 'anna:happy' to change pose (shows her if needed). |
narrate(text, options?) | A line without a speaker |
choice(options, settings?) | See Choices |
show(who, options?) / hide(who?) | Portraits; hide() clears the stage. See Portraits |
bg(id), background(x), cg(id), filter(x) | See Backgrounds |
animate, camera, shake, startShake / stopShake, flash, fade | See Effects |
rename(who, name) / reveal(who) | Change the name shown for a character, see Names that change |
movie(src, options?) | A video over the scene, see Video |
input(prompt, options?) | The player types a text, see Asking for text |
wait(ms) | A pause |
event(id, params?) | Runs another event here, in the same scene |
random() | 0..1. Use it instead of Math.random() (see saves) |
params | What the event was started with |
game | The whole game object |
Values in a line
Write {name} in the text and give the value in the options. TypeScript asks for every value the text needs, and the editor suggests their names.
await say('hero', 'Wow, you got me {count} apples!', { count: 5 })
await narrate('{name} has {gold} gold.', { name: 'Anna', gold: game.money.get(), italic: true })
- Values and style go in the same object. A value can't be named like a style option (
{speed},{color}…). - Translators see the text with its
{name}holes, so one translation works for every value (see Translations). - Markup tags (
{b},{wave}…) are not values.
Line style
await say('anna', 'WHAT?!', { size: 'large', shake: true })
await narrate('A long time ago…', { italic: true, speed: 0.5 })
| Style | |
|---|---|
italic, size ('small' | 'normal' | 'large'), color, shake | Looks of the whole line |
speed | Multiplies the player's text speed: 2 = twice as fast, 0.5 = slow and dramatic |
autoAdvance | ms after typing, then it continues by itself |
style | A named look from lineStyles in src/content/scenes.ts ({ style: 'thought' }); the other keys win over it |
as | Another name on the plate for this line (as: '???'). For a lasting change: rename |
voice | The voice number (voice: 12) or a clip by name, see Voices. Left out = no voice |
noAutoPause | Turns off the short automatic pause after . ! ? while typing (on by default) |
Text markup
await say('anna', 'Well{w=0.5}… {b}fine{/b}. {color=#e53935}Red{/color} and {wave}wavy{/wave}!')
| Tag | |
|---|---|
{b}…{/b}, {i}…{/i} | Bold, italic |
{color=#e53935}…{/color} | Colour |
{size=small|large|huge|1.4}…{/size} | Size |
{shake}…{/shake}, {wave}…{/wave} | Animated letters |
{ruby=とうきょう}東京{/ruby} | Small reading text above the letters (furigana) |
{w=0.5} | Pause while typing (seconds, default 0.5) |
| (automatic) | A short pause after . ! ? (and 。!?) when followed by a space or the end; off with noAutoPause: true |
{/} · {{ | Close the latest tag · a literal "{" |
Translations keep the tags (translate the text between them). The log shows lines without tags.
Japanese and Chinese text breaks by its own rules (no line starts with 。 or 、): the page's language is set from the language file's locale (see Translations).
Voices
await say('anna', 'Hello!', { voice: 12 }) // voice number 12
await say('anna', 'Hello again!', { voice: 'anna/hello/anna_0001' }) // a clip of another event
await say('anna', 'Nice day.') // no number = no voice (her blip plays)
await say(['jack', 'anna'], 'Bye!', { voice: { jack: 3, anna: 7 } }) // said together, two clips at once
In a .vn script the number goes in the brackets: anna(12): Hello! (see Line options).
- The file of a voice number:
src/content/audio/voice/<language>/<event id>/<speaker>_<number>.ogg(any sound format).anna(12)in the eventtown/arrivalplaysvoice/en/town/arrival/anna_0012.ogg. There is always a language folder, even when the game has one voice language. - Numbers count per event and per speaker: Anna's 1, 2, 3… and Jack's 1, 2, 3… in the same event are different files. In file names they have leading zeros; how many digits is
voice.digitsinsrc/content/scenes.ts(4 =anna_0012). In scripts you may write12or0012.pnpm story --numberwrites them for you on every line that has none (Tools); the .vn editor suggests the next free one. - Several voices on one line. Said together:
say(['jack', 'anna'], 'Bye!', { voice: { jack: 3, anna: 7 } }): the name tag reads "Jack & Anna" (text.groupNameinscenes.ts;asstill wins), the plain chat box (no character's own box, no side face), nobody of the group dimmed, the first one's blip when there is no voice. Someone else's voice under a line:say('anna', 'Hm.', { voice: { anna: 7, jack: 3 } }). All clips start together; the line counts as voiced until the longest ends (auto-play, "Voices play to the end"); each plays at its speaker's volume and mute. In .vn:jack & anna(3, 7): Bye!andanna(7, jack 3): Hm.. A clip that is not recorded yet is left out; the others still play. - Speaker in the name: the character id; a named speaker without a character (
"Student A") isstudent_a; plain narration isnarrator. - A line without a number has no voice, even when a file with a fitting name exists. Editing a line's text never changes its file.
- A number whose clip is not recorded yet plays nothing (the blip plays instead).
pnpm story --voicewritesbuild/voice-script.csv: every numbered line with its speaker, text and the file to record (see Tools). - Voice languages: the folders in
audio/voice, listed inscenes.tsasvoice.languages: ['ja', 'en']. They are their own player setting, apart from the text language: with more than one, the player picks in Settings → Audio → Voice language. The first is the default: every new player hears it, whatever their text language. A clip missing in the picked language plays from the first language in the list that has it. The names in the picker:voice.languageNames: { ja: 'Japanese' }(left out: the text language with that code, else the code). The codes need not be text languages ('dub','classic'). Music and movies in language folders follow the same setting and order. - The clip stops when the player continues, unless they turn on Voices play to the end (Settings → Audio).
- The music goes quieter while a clip plays (Lower music under voices).
- Each character with a voice clip (in any language) gets a portrait in Settings → Voices (force it with
voiced: true/falsein the character's file). The player picks a portrait (the first is picked), then sets that character's volume with the slider or mutes them with the speaker button (the slider greys out; the volume comes back on unmute). On a phone the portraits stay in one row that scrolls sideways; elsewhere they fill up to two rows, then scroll sideways (TILEandROWSat the top ofsrc/content/windows/settings/Voices.tsx). The tile shows the character's face box (the top of the default portrait when there is none). - In the log, lines with a voice have a ▶ button that plays the whole line (all its voices together; left / right step through them on a keyboard or pad).
- Favourite voices: next to ▶ each voiced line has a ☆. A starred line is kept on this device (across saves and new games, not in a save file) and plays again from Extras → Voices, where the ★ takes it off the list. In
scenes.ts:voice.favourites: { on: true, max: 200 }(on: falseremoves the star and the tab;max= how many a player can keep). From code:game.extras.favouriteVoices(),isFavouriteVoice(voices),toggleFavouriteVoice(line),playFavouriteVoice(line). The name and text are kept as they were shown (in the language played then); the clips play in the voice language set now. A line with several voices is one favourite and plays them all. - Auto waits for the clip to end, then for the auto-play pause.
- Lip sync: on a voiced line the speaker's mouth (a layered portrait with
talk) moves with the clip: open while it is loud enough, shut in its pauses and when it ends. With several voices each mouth follows its own clip (and shuts when that clip ends, while the others may go on). Lines without a clip flap while the text types (every speaker of a line said together). Tune or switch it off insrc/content/scenes.ts:voice.lipSync: { on, threshold, holdMs, checkMs }(checkMs: how often the loudness is checked).
Defaults (how much quieter, the two switches, languages, digits) are in src/content/scenes.ts under voice.
Choices
// Keys → the chosen key (typed)
const pick = await choice({
shop: 'Do you sell anything?',
past: { label: 'About your friend…', hidden: !game.flags.get('met_anna') }, // not shown
join: { label: 'Come along?', disabled: game.relationships.get('anna') < 10 && 'She doesn't know you well enough yet.' },
bye: 'Bye!',
}, { timeout: 5000, default: 'bye' }) // a bar runs out, then 'bye' is chosen
// A list → the chosen index
const i = await choice(['Rock', 'Paper', 'Scissors'])
hidden: not shown.disabled: shown greyed out; a string explains why.- No answer is focused when the choices appear, so pressing confirm quickly through the dialogue can't pick one by accident. The first down (or up) focuses the first (or last) answer; confirm picks from then on. Clicks and taps pick directly.
- Timed choices pick
default(or the first allowed option) when time runs out. - Keyboard/gamepad: up/down and confirm. A text in a variable needs
tx()to be found for translation.
Answers picked before
An answer the player has picked before, in any playthrough, is marked: choices: { markChosen: true, chosenMark: '✓ ' } in content/scenes.ts, and the look choiceChosen in content/look/parts.ts. Set markChosen: false to switch it off. Where the answers sit and how they look: src/content/ui/Choice.tsx.