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)
- Never empty: an empty answer gives
default; without one the question is asked again. - PC and phone type with their own keyboard (Enter / Done confirms). A controller gets on-screen keys: A types, B deletes. The window is
src/content/windows/textinput(key rows per language are at its top). Japanese (ja) shows hiragana, with ⇧ for katakana; the ゛゜小 key changes the last kana (は → ば → ぱ, つ → っ → づ). - The answer is part of mid-scene saves and of Back, like a choice.
- Outside events:
await game.dialog.prompt('Name?', { default, maxLength, placeholder })→ the text, ornullwhen cancelled.
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
startOnceresolvestruewhen it ran,falsewhen it was skipped.- Old saves start with nothing seen. Nested events count too.
Events inside events
await event('anna/flashback') // same scene, same stage; continues after it
- Loops are refused (a → b → a) with an error that shows the chain. Nesting stops at 8 deep.
game.events.start()during a scene queues the event to run after the current one (with a dev warning). Don'tawaitthat from inside a scene: it would wait forever.game.events.isRunning()tells if a scene is on screen.
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.
- Continue: confirm, click or tap. The first press finishes the typing.
- Skip (button, or hold Ctrl / RT): read lines fly by. Stops at unread lines (unless "Skip unread text too" is on in Settings), at choices and when the event ends. Read lines are remembered across all saves.
- With the setting Keep skipping after a choice (off for new players:
skip.afterChoiceByDefaultinsrc/content/scenes.ts), Skip turns itself back on once the answer is picked. - In visual novel mode (routes) Skip and To choice carry on from one scene of the route into the next; they still stop at choices and unread lines.
- Mouse wheel: up opens the log, down continues like a click, and down at the end of the log closes it. Switch each off in
src/content/scenes.ts:wheel: { log, advance, closeLog }. - While skipping, fades, animations, camera moves, flashes and
wait()finish at once (setting "Finish effects while skipping", on by default). Character walks on the map are not sped up. - To choice: like Skip, without stopping to show each line: straight to the next choice (or unread line).
- Auto (T, or RB on a pad): lines continue by themselves (pause set in Settings; voice lines wait for the clip).
- Q.Save / Q.Load (F5 / F9): the quick save slot. Loading asks first. See Saves.
- Back (button, PageUp / LB): one line back, or to the last choice. In a route (visual novel mode), Back on a scene's first line goes to the last line of the scene before, or to the route choice before it (asked again); the log's Jump back here reaches those earlier scenes too. How many earlier scenes:
log.backScenesinsrc/content/scenes.ts(10; 0 = only the running scene). Loading a save starts that memory over. In the normal game Back stays inside the running scene, as before. - Back keeps the scene on screen while it goes back (nothing flashes, nothing fades in again) and lands on the line as it was. Only when that takes longer than
log.backCoverMs(600 ms; a very long scene) does the replay cover show. The Back key works while choices are on screen too. - Skip back: Back again and again until pressed again, a click or confirm, picking an answer, or the start. Last choice: straight back to the last choice made, asked again.
- Log (L or View on a pad, any time; Up: W, arrow up, d-pad or stick up while no choice shows; or Menu → Log): the last 200 lines. L / View closes it again. Up / down scroll it; down at the end, cancel or ✕ closes it. While choices are on screen, up / down move between them instead.
- Hide (button, right-click, H, or Y on a pad): the box and choices step aside to show the scene. The same again, or any tap, click or confirm, brings them back. B is also cancel, which wins where something takes it (windows, the log): one press is one action, so closing a window with B never hides the box.
- On short screens (phones held sideways, under 520px tall) the box is compact: smaller text and padding. A long list of choices scrolls.
- Reading comfort (Settings → Text): text size, font, how solid the box is, Reduce shaking and flashes (no screen shake, still letters, a soft fade instead of a flash) and Read text aloud. The choices and defaults are in
src/content/scenes.ts(text,comfort). See Settings. shake()also rumbles a controller and buzzes a phone (rumbleinscenes.ts; the player can turn Vibration off).
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.
- Use
random()from the context, notMath.random(), so the replay comes out the same. - Side effects in the script (flags, items, money) simply happen again during the replay. That's correct: the game was put back to the moment the event started.
- If the script changed since the save, the replay stops where it differs and continues from there.
- Waits, tweens, walks and fades are instant during the replay.
- Toasts, sound effects and controller rumble from the script stay quiet during the replay: the player got them the first time.
- What the player does in a window while a line or choice waits (buying in a shop, using or equipping an item, changing the party) is recorded too, so it is still there after loading. Recorded parts: your
game.data, money, shop stock, party, quests, relationships, journal, names, switched-on items, difficulty, recipes and known places. - Back and "Jump back here" in the log return to the moment that line appeared: what the player did in a window while it waited is undone (money back, item gone), earlier actions are kept. Back takes the same short time however long the scene is.
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:
'screen'(default, a VN eyecatch): it covers the stage.await chapter('id')waits until it has faded in, so the stage changes after it (bg,show,hide…) happen at once under it (no fades, no slides). Once its time is up it waits until the new pictures have loaded, then fades out onto the new scene: picture X goes under the card, picture Y is already there when it leaves, nothing swaps afterwards. An event started while a card still fades in (a route'schapter()before anevent()) waits the same way.'overlay': a see-through backdrop (chapterCardOverlay) with the number, title and description over the scene; the stage stays as it is.
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.
- Picking a save in the Saves window shows: save type, play time and date, the map's title (and the event's
title, for a save made during one, e.g. Town · Jack's outfit), then the chapter (number and title) and its description. - Reaching a chapter during a scene and saving there shows the new chapter on the save, as expected.
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).