Choices and Endings
Yui found the sketchbook. Now the player decides what to do with it, and each answer leads to its own ending. On this page you add a choice, two new labels, and the statements that move between them.
How the story branches
So far the whole story is one label, 'Start'. A choice ends that label with buttons, and each button sends the story to another label:
Write the choice and the two endings
You’ll need two more backgrounds first: the palace at night, before and after its lamps light up. Add them to the list of backgrounds, under the afternoon:
// Define the backgrounds for each scene.
monogatari.assets('scenes', {
'afternoon': 'afternoon.jpg',
'night': 'night.jpg',
'nightLight': 'night-light.jpg',
});A name doesn’t have to match its file: the script calls the last one nightLight, and its file is night-light.jpg. Names can’t have spaces.
Then replace the whole script with this. The beginning is the same as before, without the 'end'; the rest is new:
monogatari.script({
'Start': [
'show scene #2b2340',
'The bell rings at the end of the drawing class.',
'show scene afternoon with fadeIn',
'Everyone hurries off, and soon the path to the Palacio de Bellas Artes is quiet.',
'Someone left a sketchbook on the low wall by the path.',
'show character y happy with fadeIn',
"y Oh, you're still here too?",
'show character y worried',
'y Hey, look. Someone forgot their sketchbook.',
{
'Choice': {
'Dialog': 'y What should we do with it?',
'Read': {
'Text': 'Read the first page',
'Do': 'jump ReadIt',
},
'Return': {
'Text': 'Find its owner',
'Do': 'jump ReturnIt',
},
},
},
],
'ReadIt': [
'show character y smiling',
'y Only the first page. Nobody will know.',
'The first page is a drawing of the palace, with two people on the path in front of it.',
'show character y happy at right',
'show character m worried at left with fadeIn',
'm That... is my sketchbook.',
'show character y worried at right',
'y Sorry, Mio. We should have asked first.',
'show character m happy at left',
"m It's fine. You two are in the drawing anyway.",
'centered Ending 1 of 2: The Drawing',
'end',
],
'ReturnIt': [
'y It says Mio on the cover. She always stays to draw the palace when the lamps come on.',
'show scene night with fadeIn',
'Night falls over the palace.',
'show scene nightLight with fadeIn',
'One by one, the lamps light up.',
'show character y happy at right with fadeIn',
'show character m happy at left with fadeIn',
'y Mio! We found your sketchbook.',
'show character m smiling at left',
'm My sketchbook! I looked everywhere for it.',
'show character m happy at left',
'm Thank you. Do you want to see what I was drawing?',
'centered Ending 2 of 2: The Lamps',
'end',
],
});Save, reload and play. After Yui’s line, two buttons appear over the palace, and her question stays in the text box while the game waits for you.

Pick one and play it to the end, then start again from the main menu and pick the other.


The choice, piece by piece
The choice isn’t a line between quotes like the other statements. It’s an object: a group of named parts between { and }, each part a name, a colon, and a value.
{
'Choice': {
'Dialog': 'y What should we do with it?',
'Read': {
'Text': 'Read the first page',
'Do': 'jump ReadIt',
},
'Return': {
'Text': 'Find its owner',
'Do': 'jump ReturnIt',
},
},
},'Choice'says what kind of statement this is.'Dialog'is a line of dialog the text box shows while the buttons wait. It’s written like any other line:y, then what Yui says.'Read'and'Return'are the two options. Their names are for you, and the player never sees them; pick any, as long as they’re different.- Each option’s
'Text'is what its button says, and its'Do'is the statement that runs when the player picks it.
Mind the brackets and commas: every { has its }, and the whole object is followed by a comma like any statement.
Labels, jump and end
'ReadIt'and'ReturnIt'are labels, like'Start'. They sit next to it insidemonogatari.script({ … }), each followed by a comma. Their order doesn’t matter.'jump ReadIt'moves the story to the first statement of the labelReadIt. Label names must match exactly, capitals included, and they can’t have spaces. When ajumpnames a label that doesn’t exist, a dialog says so as soon as the player picks that answer.'end'finishes the game and goes back to the main menu. Each ending has its own.
Two more things are new in the endings:
at leftandat rightplace a character on one side of the screen.'show character y happy at right'moves Yui, who was in the middle, to the right, and Mio comes in on the left, so the two face each other.centeredin front of a line shows it in the middle of the screen instead of in the text box, which suits an ending’s title.- Two
show scenein a row in'ReturnIt', with a line between them: night falls, then the lamps light up. A new background replaces the old one each time.
WARNING
Repeat the position every time you change a character's sprite: 'show character y worried at right', not 'show character y worried'. In Monogatari v2, a show character without at puts the character back in the middle, even when she was on one side.

TIP
When you test a branch, the Back button in the bar under the text box (or the ← key) steps the story back one line at a time, even past the choice. Go back to the choice and pick the other answer, without starting over.
Next
Music and sound: a bell, and a song for the afternoon.