Writing Dialog
Most of a visual novel is text: a narrator describing the scene, characters talking, now and then a title in the middle of the screen. This page shows how to write each of them in js/script.js, how to make words shake, wave or pause, and how to put a variable, like the player’s name, inside a line.
Every example goes inside a label of your script. Script and Labels explains labels and statements if you haven’t met them yet.
Who says a line
The first word of a line decides who says it:
| You write | The player sees |
|---|---|
'It was raining.' |
Narration: the line, with no name above it. |
'y I forgot my umbrella.' |
A character line: the name of the character whose id is y, then the line. |
'y:happy Good morning!' |
The same, with the character’s happy side image next to the text. |
'narrator next time, bring a coat' |
Narration, even though next is a word that starts a statement. |
'nvl The rain kept falling.' |
Narration on a full-screen page of text (NVL). |
'centered Chapter One' |
A line in the middle of the screen, with the text box hidden. |
Each line waits for the player: the next click, tap or key press shows the next one.
Write narration
A line whose first word is neither a character’s id nor the start of a statement (see below) is narration:
'Start': [
'show scene afternoon',
'The drawing class had ended an hour ago.',
'By now the path to the palace was empty.',
'end',
],The text box shows the line with no name.
Make a character speak
Declare the character in js/script.js with an id, a name and a color. The starter game already declares Yui as y:
monogatari.characters({
'y': {
name: 'Yui',
color: '#5bcaff',
},
});Then start a line with the id and a space:
'y I forgot my umbrella.',The text box shows “Yui” in her color above the line. If the character is on screen, their sprite gets the focus class while they speak, which your styles can use to highlight them. Characters and Sprites covers declaring characters, their sprites and side images.

Show a side image with the line
A character’s side image is a small picture of their face next to the text, one per expression. Add the expression’s name after the id, with a colon:
'y:smiling Hi, Mio! Did you finish your drawing of the palace?',
'y:worried I didn\'t either.',The expressions come from the character’s expressions, and default_expression picks the one a line without an expression shows. An expression the character doesn’t have shows no side image. Show a side image shows how to declare them.
A line that starts with an action’s word
Statements take priority over dialog. A line of narration that starts the way a statement does runs that statement instead of being shown:
'next time, bring a coat', // runs the 'next' action: nothing is shown
'end of the road', // ends the gameThese first words start a statement:
play,stop,pause,jump,end,next,clear,wait,vibrate,gallery,preload,unloadand$;showfollowed byscene,background,character,image,video,canvas,particles,message,notificationortextbox;hidefollowed bycharacter,image,video,canvas,particlesortextbox.
Two ways to write such a line:
'narrator next time, bring a coat', // 'narrator' only names the speaker
'Next time, bring a coat', // statements are case-sensitiveThe same goes for character ids: a character whose id is play or wait never speaks, because 'play Are you there?' runs the play action instead. Pick ids that aren’t on the list. With the debug module (the starter game loads it), an error dialog names such a character when the game starts.
Quotes and apostrophes inside a line
Each line is a JavaScript string between single quotes, so an apostrophe inside it ends the string early: 'y I can't wait' breaks the script. Write the apostrophe with a backslash before it, or use the typographic apostrophe:
'y I can\'t wait.',
'y I can’t wait.',Show a page of text (NVL)
In the usual mode (ADV), the text box sits at the bottom and shows one line at a time. In NVL mode the text box covers the screen and the lines pile up like the page of a book.
Start a line with nvl to show it as narration on the page:
'Start': [
'show scene afternoon',
'nvl The drawing class had ended an hour ago.',
'nvl By now the path to the palace was empty, except for the two of us.',
'nvl Yui was still on the low wall, pretending to draw.',
'clear',
'nvl She closed her sketchbook at last.',
'y Are you waiting for me?',
'end',
],
clearempties the page; the nextnvlline starts a new one.- A line that isn’t NVL (here, Yui’s) turns the text box back into the usual box at the bottom.
show sceneempties the page too, and the next line starts a fresh one.- A character can speak in NVL mode: give the character
nvl: trueand all of their lines go on the page, with their name in front. See Characters and Sprites. - A choice shown on an NVL page appears inside the page, under the last line.
Dialogs and Clear have the details.
Show a line in the middle of the screen
Start a line with centered for a chapter title, a date, or a thought that stands apart:
'centered Chapter One: After the Bell',The text box hides, and the line appears in the middle of the screen. The next click takes it away, and the next line brings the text box back.

The centered line has the text box’s colors, white text on a translucent dark box, so it reads over light and dark scenes. To drop the box and keep the text, add this to style/main.css:
centered-dialog {
background-color: transparent;
color: #ffffff;
}Bold, italics and line breaks
A line can hold HTML: <b> for bold, <i> for italics, <br> to break the line.
'y Did you hear that? It came from <i>inside</i> the library.',
'Roses are red,<br>violets are blue.',Style one line
Add a class name after the expression, with a second colon, to put that class on the text box for that line only. Several classes go together with |:
'y:happy:shout Stop right there!',Then style it in style/main.css:
/* A line written as 'y:happy:shout …' */
text-box.shout [data-ui="say"] {
font-size: 1.5em;
text-transform: uppercase;
}The line shows in larger capitals; the next line takes the class off again. A line without an expression leaves the middle empty: 'y::shout Stop!', 'narrator::shout Stop!'. Text Box lists the parts of the text box you can style.
Make words shake, wave or pause
Inside a line, words between two text effect markers move or look different. The opening marker is the effect’s name in braces; the closing one has a slash:
'y:worried The review is {big}tomorrow{/big}? And it covers {rainbow}everything{/rainbow}? I have a {bold}terrible{/bold} feeling about this.',
The effects that come with Monogatari:
| Kind | Effects |
|---|---|
| Move while on screen | shake, shake-hard, shake-slow, shake-little, shake-horizontal, shake-vertical, wave, wave-slow, wave-fast, glitch, glitch-hard, glitch-slow, static, rainbow, glow |
| Play once as each letter appears | fade, fade-slow, blur, scale, scale-bounce, slide-up, slide-down, impact, redacted, invisible-ink, handwriting, strike, flicker |
| Moods | angry, scared, happy, sad, mysterious, excited, shout, dizzy, dreamy |
| Plain styling | bold, italic, big, small, whisper, robotic |
Effects show however the line appears: typed letter by letter, all at once because typing is turned off (see below), or finished by the player’s click. An effect that plays as each letter appears, such as fade, plays on the letters still to come when the click shows them. Before 2.9.0, a line that appeared at once lost its effects.
Pause, or change the typing speed
Two markers change how the line types out, instead of how it looks:
{pause:N}stops the typing for N milliseconds at that point:'y Well...{pause:800} fine.'waits a little under a second before “fine.”{speed:N}types the rest of the line at N percent of the current speed:{speed:50}is half as fast,{speed:200}twice as fast. The next line starts at the player’s speed again.
Write the markers exactly as shown, with no space after the colon: {pause: 800} is shown as text in the line.
The dialog log gets the line without its markers.
Type Writer has every marker’s details, and how to add your own.
Typing speed, and turning the typing off
Lines type out letter by letter. The player sets the speed with the Text Speed slider of the settings screen. A click while a line is still typing finishes it: the starter game shows the rest at once ('InstantText': true in js/options.js).
To stop lines from typing out, change these settings in js/options.js:
| Setting | What it turns off |
|---|---|
'TypeAnimation': false |
Typing for every line in the game, and the Text Speed slider. |
'NarratorTypeAnimation': false |
Typing for narration. |
'CenteredTypeAnimation': false |
Typing for centered lines. |
'NVLTypeAnimation': false |
Typing for lines on an NVL page. |
For one character, add type_animation: false to the character. Configuration describes every setting.
Put a variable in a line
Write a variable’s name between double braces and the line shows its value:
'y Nice to meet you, {{player.name}}!',
'You have {{coins}} coins left.',The variables come from the game’s storage, which js/storage.js declares (the starter game declares player.name and asks for it at the start). A dot goes into a nested value: {{player.name}} is the name inside player. Variables and Storage explains how to declare and change them.
- A variable that doesn’t exist opens a dialog while you develop, titled
Variable "{{coins}}" does not exist in your storage, and the line shows the variable as you wrote it: “You have {{coins}} coins left.” Declare every variable injs/storage.js, even the ones you only set later. - The value is shown as text. If the player types
<b>Kim</b>as their name, the line shows<b>Kim</b>, tags included, so nothing a player types can change the page. The line’s own words keep their HTML:'Hi <b>{{player.name}}</b>!'shows the name in bold. If your own variables hold HTML on purpose, set'AllowHTMLInVariables': trueinjs/options.jsto show it as HTML, but only when no variable holds what a player typed. Before 2.9.0, values were shown as HTML, and a missing variable emptied the whole line. - Variables work in every statement, not only in dialog:
'jump {{route}}'jumps to the labelroutenames, a choice’s button text can hold one, and a character’snamecan be'{{player.name}}'for the player’s own character.
To ask the player for a value, like their name, use the Input action.
Lines in several languages
A game in several languages has one script per language, and a line can name a translated text with a _(Key) marker. Translating Your Game explains both.
Related
- Dialogs: the full reference for dialog lines.
- Characters and Sprites: declare characters, their sprites and side images.
- Text Box, Type Writer and Centered Dialog: the components that show the text.
- Dialog Log: the log of past lines the player can open.