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:

flowchart TD start["Start<br/>(the afternoon)"] --> choice{"What should we<br/>do with it?"} choice -->|Read the first page| read["ReadIt<br/>(Mio finds you reading)"] choice -->|Find its owner| ret["ReturnIt<br/>(the lamps come on)"] read --> end1(["Ending 1: The Drawing"]) ret --> end2(["Ending 2: The Lamps"])

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.

The palace in the afternoon with Yui in the middle, looking worried. Two buttons over her read "Read the first page" and "Find its owner", and the text box shows Yui asking "What should we do with it?"
The choice waits until the player picks an answer.

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

The palace in the afternoon. Mio, a girl with long dark hair and a white dress, smiles on the left, and Yui, looking worried, stands on the right. Mio says "It's fine. You two are in the drawing anyway."
Ending 1, in the afternoon.

The palace at night, its lamps lit under a crescent moon. Mio stands on the left and Yui on the right, both smiling. Mio says "Thank you. Do you want to see what I was drawing?"
Ending 2, once the lamps are on.

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 inside monogatari.script({ … }), each followed by a comma. Their order doesn’t matter.
  • 'jump ReadIt' moves the story to the first statement of the label ReadIt. Label names must match exactly, capitals included, and they can’t have spaces. When a jump names 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 left and at right place 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.
  • centered in 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 scene in 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.

The palace with Yui in the middle, looking worried, and Mio on the left. Yui says "Sorry, Mio. We should have asked first."
Without "at right", Yui walks back to the middle when her expression changes.

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.