Skip to content

Latest commit

 

History

History
170 lines (123 loc) · 7 KB

message.md

File metadata and controls

170 lines (123 loc) · 7 KB
title Message
order 19
description Show a window with a title, a subtitle and longer text, such as a letter or instructions, that the player closes to go on.

Message

show message opens a window over the game with a title, a subtitle and a body. Use it for text longer than a line of dialog: a letter, an email, instructions, a journal entry. The player reads it and closes it with its button to go on. You register each message once, under a name, and show it from the script by that name.

A white window titled "A Letter From Home", with the subtitle "From Mom", the letter and a "Fold the letter" button, over the palace|The letter from the example below, with a button label of its own

Syntax

'show message <name> [<classes>…]'
Part Type Default What it does
<name> text (required) The name the message was registered with. Names are case-sensitive.
<classes> words none Any other words are added as CSS classes to the message-modal element, so you can style one message differently.

Register a message

Register your messages in js/script.js. The starter game already registers one, called Help, at the top of that file:

monogatari.action('Message').messages({
  'Letter': {
    title: 'A Letter From Home',
    subtitle: 'From Mom',
    body: 'Hope you are doing well, {{player.name}}. Come visit soon.<br><br>Love, Mom',
  },
});

Each call adds to the messages already registered, so you can register them in several places. {{player.name}} is the player's name, which the starter game asks for in its first statements and keeps in the player variable that js/storage.js declares.

Property Type Default What it does
title text none The heading of the window. Left out or empty, the window has no heading.
subtitle text none A smaller line under the heading.
body text none The message itself. It can hold HTML (see below).
actionString text 'Close' The label of the button: the text itself, or the key of a translation. See Change the button's label.

{{variables}} work in all four (see Variables in statements). Their values are shown as text: HTML in a value shows as written, while the HTML you write in the message works.

The body goes inside a paragraph (<p data-content="body">), so write it with inline HTML: <br> for a line break, <em>, <strong>, <a>, <img>. Block elements such as <p>, <div> or <ul> close that paragraph: they still show, but after it instead of inside it.

Games written for Monogatari v1 named the properties Title, Subtitle and Message. A message that has all three of those is still shown correctly.

Show a letter

The whole example, for js/script.js:

monogatari.action('Message').messages({
  'Letter': {
    title: 'A Letter From Home',
    subtitle: 'From Mom',
    body: 'Hope you are doing well. Come visit soon.<br><br>Love, Mom',
  },
});

monogatari.assets('scenes', {
  'afternoon': 'afternoon.jpg',
});

monogatari.characters({
  'y': {
    name: 'Yui',
    color: '#c28cf0',
  },
});

monogatari.script({
  'Start': [
    'show scene afternoon',
    'y There is a letter in my bag.',
    'show message Letter',
    'y I should call her more often.',
    'end',
  ],
});

Put afternoon.jpg in assets/scenes/. After Yui's first line, the next click opens the letter. Clicking Close closes it, and Yui's second line shows.

Change the button's label

Write the label itself:

monogatari.action('Message').messages({
  'Letter': {
    title: 'A Letter From Home',
    subtitle: 'From Mom',
    body: 'Hope you are doing well. Come visit soon.<br><br>Love, Mom',
    actionString: 'Fold the letter',
  },
});

The button reads Fold the letter.

In a game in several languages, use the key of a translation instead, so the button follows the player's language, also when they change it while the message is open. Monogatari's own keys work as they are ('Close', 'OK', 'Back', 'Cancel'…). For a label of your own, add a key to the translations of each language, then use the key:

monogatari.translation('English', {
  'CloseLetter': 'Fold the letter',
});

monogatari.translation('Español', {
  'CloseLetter': 'Doblar la carta',
});
actionString: 'CloseLetter',

A label that is a key in English but not in the player's language shows in English. See Translating your game. Before 2.9.0, only keys worked: a label written as text showed undefined.

Style one message

Extra words after the name become classes on the message-modal element:

'show message Letter handwritten'

Then, in style/main.css:

message-modal.handwritten [data-content="body"] {
  font-style: italic;
}

The parts of the window are [data-content="title"] (an h3), [data-content="subtitle"] and [data-content="body"] (paragraphs) and the button, [data-action="close"]. See the message modal component for its markup and styles.

How it advances

The game waits for the player. While the message is open, clicks on the game and the advance keys (right arrow, space bar) do nothing, and auto-play waits. Clicking the button closes the message and runs the next statement.

Esc doesn't close the message: it opens the settings screen, as it does during the rest of the game, and the message is still there when the player comes back.

Showing a name that was never registered fails: see What the debug module reports and When a statement fails.

Going back

show message is a statement the player stops at.

  • Going back from the line after a message opens the message again. The line the player went back from stays in the text box behind it until they close the message.
  • Going back while the message is open closes it and returns to the line before it.

What the debug module reports

Dialog title When What to do
The message "<name>" was not found No message is registered under that name. The dialog lists the registered ones under You may have meant. Fix the name (it's case-sensitive), or register the message.
Translation for string "<key>" could not be found The message's actionString is a key English has, but the player's language doesn't. The button shows the English text. Add the key to that language with monogatari.translation(): see Change the button's label.

Related pages