Events: flow, saves & endings

How scenes run and end: asking for text, running once, events inside events, what the player can do (skip, auto, back), saving in the middle of a scene, chapters, endings and replays.

Asking for text

const name = await input('What should I call you?', { default: 'Alex', maxLength: 12 })
await say('anna', 'Nice to meet you, {name}!', { name })
game.state.update((d) => { d.playerName = name })   // keep it in your saved data (add playerName to content/save/data.ts)

Run once

The game remembers which events have started in this playthrough (saved with the game). Use that for scenes that should happen once, instead of a hand-made flag:

// A map object (e.g. a tile you step on)
onEnter: ({ game }) => game.events.startOnce('heaven/before_god/meeting'),

// Anywhere else
if (!game.events.seen('heaven/before_god/meeting')) { … }
game.events.count('anna/hello')    // how many times it started
game.events.finished('anna/hello') // it ran to its end at least once

Events inside events

await event('anna/flashback')            // same scene, same stage; continues after it

Event params

defineEvent({ title: 'Greeting', run: async ({ params, say }: EventContext<{ name: string }>) => { … } })
game.events.start('greet', { name: 'Ola' })     // params are now required and typed

What the player can do

The speaker's name sits on the dialogue box's top border. The toolbar (by default a row along the box's bottom, at the right: where) has Settings, Lock (only when it auto-hides), Save, Load, Q.Save, Q.Load, Skip back, Last choice, Back, Auto, To choice, Skip, Flowchart (visual novel mode), Replay voice, favourite Voices and Hide (what each does). The Log is in the pause menu.

Jumping back from the log

In the log, left / right pick a line of the running scene and Jump back here returns to it (the same as pressing Back that many times). Lines from earlier scenes can only be jumped to in a route (see Back above). Switch it off with log: { jumpBack: false } in content/scenes.ts. The log's layout (panel, line layout, button symbols): src/content/ui/Log.tsx.

Saving in the middle of a scene

Players can save while a line or choice is on screen. The save holds the game as it was when the event started, plus a record of the lines seen, choices made, minigame results and random numbers. Loading replays the event instantly (behind a black cover) up to the saved line.

A battle inside an event is not fought again on load: its result, the HP left, the items used and the rewards are stored with the save and put back at that point of the scene. Your own engine code with a result that can't be replayed can do the same: const mark = gameMark() before it and settleGame(mark) after it (core/scene/replay.ts).

Chapters

Labels for the story's parts. A save shows its chapter instead of the place, and picking a save shows the chapter's title and description, so the player knows where the story is before loading it. Every chapter has a number, an optional sub chapter (1.2), a title and a description. In visual novel mode a route can start one too, and the flowchart draws a line for each new chapter number (never for a sub chapter).

// src/content/chapters.ts
export default defineChapters({
  announce: 'card',                // 'toast' (a small message), 'card' (full screen), 'both', or false
  card: { style: 'screen', ms: 2800, fadeMs: 600, skippable: true },   // the chapter card (below)
  label: tx('Chapter {number}'),   // how a number reads: {number} = 1, or 1.2
  vn_chapters: { 0: tx('Prologue'), 1: tx('Spring') }, // a name per number instead of label (others: label)
  full: tx('{label}: {title}'),    // on saves and in the toast
  chapters: {                      // ordered by number, then sub
    heaven:  { number: 0, title: tx('Before God'), description: tx('Where it all starts.') },
    town:    { number: 1, title: tx('The town'), image: townPicture },  // image: on the card
    evening: { number: 1, sub: 2, title: tx('The last bus'),       // "Chapter 1.2: The last bus"
               card: { style: 'overlay' } },                    // its own card (any card option)
    finale:  { number: 9, title: tx('Finale'), screen: FinaleCard },  // its own drawing
  },
})

await chapter('town')              // in a scene: begins it and waits for a 'screen' card to cover (`chapter town` in .vn)
game.chapters.reach('town')      // anywhere else (a map's onEnter…): begins it, does not wait
game.chapters.current()          // the chapter the game is in (saved)
game.chapters.info('town')       // { number, sub, title, description }
game.chapters.label('evening')   // "Chapter 1.2" (translated)
game.chapters.numberLabel(1)     // "Chapter 1" (the flowchart's heading for every 1.x)
game.chapters.fullTitle('town')  // "Chapter 1: The town" (translated)

The chapter card (announce: 'card' or 'both') comes in two styles:

card: {
  style: 'screen',
  ms: 2800, fadeMs: 600,          // time on screen with both fades; or fadeIn / fadeOut
  steps: [800, 1500],              // instead of ms: like a boot screen, the card's `step` prop counts them
  skippable: true,                 // click / tap / confirm (it still waits for the pictures)
  maskIn: 'irisOut', maskOut: 'wipeLeft',   // a mask transition from scenes.ts instead of a fade ('screen' only)
}

The next line, choice or text input waits for the card in both styles, so the scene goes on after it. The drawing (src/content/ui/ChapterCard.tsx, or a chapter's own screen component) gets label, title, description, image, style, shown + fadeMs (fade with them), phase ('in', 'on', 'out'), step and skipped: CSS animations can run while phase is 'on', and show their end at once when skipped. A click, a tap or confirm skips it (skippable). It never shows while a loaded save replays its scene, while skipping, or in a scene watched from Extras. Reduce shaking and flashes drops the fades. Looks: the chapterCard, chapterCardLabel, chapterCardTitle, chapterCardDescription and chapterCardOverlay parts in src/content/look/parts.ts; a chapter's image shows on a 'screen' card.

Endings

// src/content/endings/true_end/index.ts
export default defineEnding({
  title: 'Together',
  description: 'You left the town with Anna.',
  hint: 'Trust someone.',        // shown while it is still locked
  // image, order: 1, secret: true (not listed or counted until reached)
})

ending('true_end')                 // in an event: reached, for good, in every save
await game.windows.open('credits')
game.session.leave('title')

ending() only records it: end the event and leave the game yourself. Reached endings are listed in Extras → Endings, count towards the completion percentage, and (by default) unlock New Game+. From code: game.extras.reachEnding(id), endingReached(id), endings().

Replayable scenes

defineEvent({ title: 'The pond', replay: 'The pond', run: async (ctx) => { … } })   // listed in Extras → Scenes once finished
defineEvent({ title: 'The pond', replay: { title: 'The pond', preview }, run: … }) // with a card picture (import preview from './preview.png')

See Extras. Keep replayable events to the scene itself (no map changes).