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.

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, fadeSee 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)
paramsWhat the event was started with
gameThe 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 })

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, shakeLooks of the whole line
speedMultiplies the player's text speed: 2 = twice as fast, 0.5 = slow and dramatic
autoAdvancems after typing, then it continues by itself
styleA named look from lineStyles in src/content/scenes.ts ({ style: 'thought' }); the other keys win over it
asAnother name on the plate for this line (as: '???'). For a lasting change: rename
voiceThe voice number (voice: 12) or a clip by name, see Voices. Left out = no voice
noAutoPauseTurns 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).

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'])

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.