# Writing scenarios

This document covers how to write scenario files (`.lim`) and what the syntax check (`lim check`) looks for.
The parameters of each command are in [commands.md](../commands.md), and the screens and game settings are in [player.md](../player.md).

In this document:

1. Concepts: why the format looks like this
2. Kinds of lines: dialogue, narration, commands, labels, comments
3. Writing inside text: ruby, emphasis dots, text decoration, click waits, inline commands
4. Vertical writing and NVL
5. Writing commands: value types, parameter rules, waiting for effects, `@html`, `@script`
6. Sprites
7. Voice
8. Conditions, choices, variables, macros
9. Syntax check
10. Project files
11. An example of importing from TyranoScript
12. `lim` commands

## 1. Concepts

.lim was made to remove, through the rules of the format itself, the places where writing a scenario tends to go wrong. Instead of finding mistakes afterwards, it makes them hard to make.

| Where writing tends to go wrong | How .lim handles it |
|---|---|
| Implicit rules (a forgotten click wait, a speaker carried over from an earlier line) | One line is one click. A dialogue line carries its own speaker |
| Symbol collisions (symbols written in the text are read as commands) | The only special characters in text are `{` `}` `\` |
| Mistyped values that only show up when you run the game | There are types such as durations, numbers, booleans and colors, and the syntax check checks them |
| Errors that don't tell you where or what went wrong | Problems are reported before running, with the line and a suggested fix |
| Gaps filled with free-form scripts, so every game is written differently | `@html` without JS for display. Logic goes in plugin commands. `@script` is a place to keep imported JS until it's rewritten, and it doesn't run |

Two more things are assumed.

- **You write together with AI.** Whether a person or an AI writes it, the result has the same form, a machine can check it, and mistakes show up right away with their position.
- **Existing TyranoScript games can be imported.** Import .ks with `lim import` and run it as is (chapter 11).

### Seven principles

| Principle | What it means |
|---|---|
| How parameters are written | Unnamed parameters can't be written with a name. A named boolean can be written as just its name instead of writing `true` |
| Each line stands on its own | A dialogue line carries its own speaker and doesn't depend on the state of the line before it. Whichever line you take out and edit, the speaker assignment and line structure don't break |
| Text appears as written | The only special characters in text are `{` `}` `\`. `{` always starts some syntax, and if it doesn't match any, it's an error (it isn't silently shown as a character) |
| Command specs live in one place | The syntax check, completion, reference and runtime read the same definitions, so the reference and the actual behavior don't drift apart |
| Mistakes are caught before running, with the position and a fix | Diagnostics have the line, column, identifier and a suggested fix (hint) (chapter 9) |
| Results of running can be inspected by machine | Running without a browser gives the results as JSON, and screenshots of a given line can be taken (`lim trace`, `lim shot`) |
| Randomness and time can be fixed | The same input gives the same result |

## 2. Kinds of lines

The extension is `.lim`. It's line-based UTF-8 text. Write one unit, such as a chapter, per file, and divide it with labels.

```
# north_road
// Flashback starts here
@chara Yuika smile at=left time=300ms
Outside the window, the rain was letting up.
Yui "Morning. You're up early today."
```

The kind of line is decided by how the line starts.

| Line starts with | Kind | Example |
|---|---|---|
| A speaker name immediately followed by `「` `『` `（` `(` | Dialogue | `ユイ「おはよう、今日は早いのね」` |
| A speaker name followed by `"` `“` (one half-width space may come between them) | Dialogue (English) | `Yui "You're early today."` |
| `@` | Command | `@chara Yuika smile at=left time=300ms` |
| `# ` | Label | `# north_road` |
| `//` | Comment (only at the start of a line; it can't be written at the end of a line) | `// Flashback starts here` |
| Empty line | Separator (no meaning) | |
| Anything else | Narration | `Outside the window, the rain was letting up.` |

Narration and dialogue are **one click per line**.
To stop in the middle of a line, write `{click}`; to break the line within the same page, write `{br}` (chapter 3).
To move on to the next line at the end of a line without waiting for a click, write `{noclick}` at the end of the line (chapter 3).
After a click moves on to the next page, the first command (a background, a sprite, a wait and so on) clears the previous page's name and text. With `ui.message.keepText` set to `true` in liminalia.json, they stay until the next text (for a single line, `keep-text=true` on `@bg`).

### What makes a line dialogue

Only lines that meet both of these conditions become dialogue.

1. The line starts with a speaker name registered in the project
2. Right after it comes one of `「` `『` `（` `(`, or a quotation mark `"` `“` follows it (you may write a single half-width space between the speaker name and the quotation mark)

Everything else is narration. `It was "love."` is narration, because "It was" isn't a speaker. (`「」` and `『』` are Japanese quotation marks, called corner brackets.)

Brackets and quotation marks are part of the text, and the game shows them as written (`ユイ「おはよう」` shows `「おはよう」`, and `Yui "Hello."` shows `"Hello."`).
The space before a quotation mark isn't part of the text, so the text starts at the quotation mark. To show the text without the outer brackets or quotation marks, set `ui.text.quotes` in liminalia.json to `strip` (appearance settings in chapter 4).

```
Yui "Hello."
Yui“Wait for me!”
Yui{name ???} "Who are you?"
```

- Only the start of the line is checked. The closing quotation mark isn't (just as with Japanese brackets, a line missing its closing mark is still dialogue). `“` closes with `”`, and `"` closes with `"`.
- Single quotation marks (`'` `‘`) don't make a line dialogue, because they can't be told apart from apostrophes in English text.
- Only a single half-width space is allowed. Two or more spaces, a full-width space or a tab make the line narration. With a Japanese bracket, even a single space before it makes the line narration.
- A line where a symbol follows the name, such as `Note: "x"`, and a line that starts with a name that isn't registered are narration.

The speaker name is the name shown in the name box (`Yui`, `???`, `Clerk` and so on). Register it in `speakers` in cast.json, separately from the character who owns the sprites (chapter 10).

**If a line meant as dialogue becomes narration, you get a warning.** A line where "a bracket or quotation mark starts after the name at the start of the line and closes at the end of the line" but which became narration gets the
`unknown-speaker` warning. The cause is usually one of the following, and if there is a speaker name with a similar spelling, it appears in the suggested fix.

- A misspelled speaker name
- A speaker you forgot to register
- A space between the name and the bracket (`ユイ 「…」`). For a quotation mark, a space that isn't a single half-width space (`Yui  "…"`, `Yui　"…"`)
- Habits from other script formats (`ユイ：「…」`, `【ユイ】「…」`, or `ユイ：…` with a registered speaker)
- The screenplay form with a half-width `:`. It warns only for a registered speaker's line, a line with a Japanese bracket after the colon (`ユイ:「…」`), and a line whose name starts with an uppercase letter when the same name appears on two or more lines of the same file (`Nora: "…"`). A single `Note: "x"` line stays narration without a warning
- A display name on a name that isn't registered (`Kai{name ???} "…"`). `{name …}` works only on a speaker's line, so adding the name to the speakers makes it dialogue

The suggested fixes are the line rewritten as dialogue (a replacement) and, for a name that isn't registered, "Add to speakers" (`add-speaker` in `fixes`).
To write narration shaped like dialogue on purpose, indent the start of the line with a full-width space (U+3000) (this is advice for Japanese projects; projects whose source language isn't Japanese aren't told to use a full-width space).

**Symbols typed with Japanese input still on are warned about too.** A full-width `＠` `＃` `／／` at the start of a line doesn't make a command, label or comment, and becomes text.
A full-width `＝`, as in `time＝300ms`, is still read but should be fixed (`fullwidth-symbol`; the suggested fix is the line with half-width characters).
A choice line written outside `@choice` (`- … -> target`) becomes text (`option-outside-choice`).
A `//` at the end of a line doesn't make a comment (`trailing-comment`; on command and choice lines it's an error and nothing from `//` on is read; on dialogue and narration it's a warning and it's shown as text).

### Changing the name in the name box (display name)

Keep the character as is and change only the name shown in the name box (a hidden identity such as "???", a name the player entered, a scene that reveals a real name, and so on).
Lip sync, dimming characters who aren't speaking, the balloon position, per-speaker volume, voice numbering and the name color keep working as the speaker.

```
Yui{name ???} "...Who are you?"
Hero{name {= game.player}} "I'm—"

@name Yui as=???
Yui "I'm no one worth naming."
Yui "...Not yet, anyway."
@name-off Yui
Yui "I'm Yui. Nice to meet you."
```

| How to write it | How long it lasts |
|---|---|
| Speaker{name Display name}「…」, Speaker{name Display name} "…" | That line only. Write `{name …}` right after the speaker name, before the bracket or quotation mark. Only characters and `{= expression}` can go inside |
| `@name speaker as=name` | Until `@name-off speaker` (omit the speaker for all). `as=(expression)` lets you use a variable (the value at the time this command runs is used) |

- `{name …}` on a line takes priority over `@name`.
- The keys of a line (translation, locked voice numbers, read status) are made from the speaker name and the text. The display name isn't part of the key, so a display name doesn't detach the translation or the voice number, and doesn't change the read status.
- In translation files, display names written as plain text are listed in `speakers` too, just like speaker names (Languages in chapter 10).
- The backlog, NVL, the chat screen and text-to-speech show the display name.

### Labels

- Write `# name`. A name can contain letters, digits, `_` and `-`.
- `#name` (no space) is an error (`bad-label`), with a suggested fix.
- Labels can't be placed inside `@if` (chapter 8).

### Indentation and escapes

- Half-width spaces and tabs at the start of a line are indentation and have no meaning.
- **Full-width spaces aren't removed.** Indent text with full-width spaces (U+3000, the usual way to indent a paragraph in Japanese).
- To show a symbol at the start of a line as text, put `\` before it (`\# is not a label`).

### Fixed line IDs (#line:)

At the end of a dialogue, narration or choice line, you can write `#line:ID` after a half-width space or a tab (like `#line:` in Yarn Spinner and `id` in Ren'Py).
An ID can contain letters, digits, `_` and `-`. Everything from `#line:` on isn't part of the text.

```
Yui "Morning. You're up early today." #line:3f2a91c0
Outside the window, the rain was letting up. #line:intro-rain
@choice
  - Check the door -> #door #line:0b7d44e1
@end
```

- On a line with an ID, the translation key and the key of the locked voice number no longer depend on the original text. Fixing the original a little doesn't detach the translation, and it keeps being used (Languages in chapter 10).
  The recorded voice number stays too, and lines whose original changed appear under "needs re-recording" in the recording script.
- `lim i18n --stamp-ids` gives IDs to lines without one (and moves the translation files and the locked voice numbers to ID keys too). You can also write them by hand.
- Using the same ID twice in the same file is an error (`duplicate-line-id`). A character that can't be used after `#line:` is a warning (`bad-line-id`), and the line ID part is shown as text too.
- To show `#line:` as text, write `\#line:`.

## 3. Writing inside text

Inside dialogue and narration, you insert syntax with `{ … }`. The only special characters in text are `{` `}` `\`;
`&` `%` `[` `]` `#` `:` and the rest all appear as plain characters.

### Overview

| Kind | How to write it | Meaning |
|---|---|---|
| Ruby and emphasis dots | `{r 漢字\|かんじ}` | Ruby (a small reading printed above the characters). The base text can be any number of characters |
| | `{dot 大事}` | Emphasis dots (small dots by each character, used for emphasis in Japanese) |
| Text decoration | `{b bold}` `{i italic}` | Bold, italic |
| | `{c #cc3333 colored}` | Text color |
| | `{size 32 big text}` | Text size (px) |
| | `{mark #ffff66 marked}` | Background color, like a highlighter |
| | `{fx wave wavy text}` `{fx wave strength=2 speed=0.5 text}` | Text motion (table below; you can also set the size and speed of the motion) |
| Progress | `{click}` | Wait for a click in the middle of a line (`[l]` in .ks) |
| | `{noclick}` | At the end of the line, move on to the next line without waiting for a click (only at the end of a line; see below) |
| | `{br}` | Line break within the same page (`[r]` in .ks) |
| | `{speed 600ms ...}` | Change the text speed for the enclosed part only (time per character) |
| Embedding | `{= game.name}` | Embed a value |
| | `{img icons/heart.png}` `{img icons/heart.png 32}` | An image in the text |
| | `{@chara Yuika smile}` | Run a command when the text reaches that point |
| Variations | `{seq first time\|second time}` `{cycle morning\|night}` `{once Nice to meet you\|}` `{shuffle red\|blue}` | Each time the same place is passed, shows one of the parts separated by `\|` (see below) |
| Escapes | `\{` `\}` `\\` | `{` `}` `\` themselves (inside variations, a literal `\|` is written <code>&#92;&#124;</code>) |

- Text decoration (`b` `i` `c` `size` `mark` `fx`) and emphasis dots can be nested (`{b {c #cc3333 bold red}}`).
- `{img}` images are looked up in the `image` folder. The height is in px; if omitted, it's the text size. The image is shown as one character and appears in the backlog too. It's included in the exported assets.

Motions of `{fx}`:

| Name | Motion |
|---|---|
| `shake` | Trembles |
| `wave` | Waves |
| `pop` | Bounces in |
| `fade` | Slowly fades in |
| `glow` | Glows |

After the name, you can write multipliers for the size of the motion (`strength=`) and its speed (`speed=`) (1 is standard; in this order, and either can be omitted).

```
Yui "{fx shake strength=3 speed=2 Scary}..."
{fx wave strength=0.5 speed=0.5 Gently swaying}
```

- `strength` multiplies the width of shaking and waves, the spread of the glow, and the size and blur when appearing; `speed` multiplies the speed of the motion. Write positive numbers; anything else is an error (`bad-fx`).
- An inner `{fx}` doesn't inherit the outer `strength` and `speed`.
- `lim backport` can't write `{fx}` back (it removes the motion and reports it).

### Variations (`{seq …}` `{cycle …}` `{once …}` `{shuffle …}`)

When the same line is passed many times (an investigation screen, a choice the player comes back to, and so on), the text shown changes each time. They're the same as Ink's sequences (`{A|B}` `{&A|B}` `{!A|B}` `{~A|B}`).

```
# desk
{once There's an old letter on the desk.|}{seq You read the letter.|You read it again.|You know it by heart now.}
Yui "{shuffle Right|Yeah|...Mm}"
@jump #menu
```

| How to write it | How it's shown |
|---|---|
| `{seq a\|b\|c}` | Shown in order each time it's passed, and the last one, `c`, keeps being shown |
| `{cycle a\|b}` | Shown in order each time it's passed, going back to the first after the last |
| `{once a\|b}` | Shown in order, each one only once, each time it's passed. After all of them have been shown, nothing is shown (you can write an empty part too, as in `{once Nice to meet you\|}`) |
| `{shuffle a\|b\|c}` | Chosen at random each time it's passed. The same one isn't shown twice in a row |

- The separator is a half-width `|`. Write a literal `|` as `\|`. Each part can contain ruby, `{= expression}` and text decoration (`{seq {r 星\|ほし}が{= n}つ\|…}`).
- How many times it has been passed is kept in the save (per playthrough, like `visits`). Saving in the middle of a page and loading shows the same text.
- The counts are kept separately by file, by line (its original text) and by which variation it is within that line. Lines with the same text in the same file share their counts.
- Random choices follow the project's random seed (`lim coverage --seeds`). Variations can be written in choice text too.
- Translations translate the whole line (write the same number of variations in the translated text too). Character counts and search count the text with all the parts joined by `/`.
- TyranoScript has no equivalent, so `lim backport` writes back only the first part and reports it as something it can't write back. `lim import-ink` turns Ink's sequences into this syntax (sequences inside conditional branches don't become variations; they become expressions).

### Ruby

Ruby is a small reading printed alongside the text, mostly used to give the kana reading of kanji, so the examples are in Japanese.

```
{r 漢字|かんじ}を読む
{r 東京特許許可局|とうきょうとっきょきょかきょく}
{b {r 漢字|かんじ}}
```

- The base text and the reading are plain characters without decoration, and `{…}` can't be written inside them. To decorate ruby, enclose it from outside (the third example).
- Neither the base text nor the reading can be empty (`empty-ruby`).
- `{r 漢字}`, missing the `|` that separates the reading, and `{r 漢字｜かんじ}`, separated with a full-width `｜`, are errors (`bad-ruby`; the full-width `｜` is read as ruby, and the suggested fix is the line with a half-width one).
- Ruby written in other formats (`｜漢字《かんじ》`, `漢字《かんじ》`) doesn't become ruby and is shown as is, so it's warned about, with a suggested fix that rewrites it as `{r 漢字|かんじ}` (`aozora-ruby`).
- `\` makes the next character a plain character. To put special characters in the base text or the reading, write them as follows.

| Character | In the base text | In the reading |
|---|---|---|
| `\|` | <code>&#92;&#124;</code> | Write it as is (the reading lasts until `}`) |
| `{` `}` | `\{` `\}` | `\{` `\}` |
| `\` | `\\` | `\\` |

- Change the ruby size with `ui.text.rubySize` in liminalia.json (a multiple of the base text size; default 0.45).
  The position of ruby in vertical writing is calculated from this value, so **don't override the `font-size` of ruby directly in the project's CSS.**
- In vertical writing, ruby goes to the right of the characters.

### Emphasis dots

Emphasis dots (boten) are small marks placed by each character to emphasize a word in Japanese, so the examples are in Japanese.

```
それは{dot 大事}なことだ
{b {dot 強調}}
```

- The shape is set by `ui.text.emphasis` in liminalia.json. The value is a CSS `text-emphasis-style`, and the default is `filled sesame` (sesame dots).
  Others include `filled dot` and `open circle`.
- They can be nested with text decoration.

### Inline commands

`{@…}` runs a command when the text reaches that point. Use it, for example, to change an expression right after a click wait.

```
Yui "And?{click}{@chara Yuika angry} ...Are you even listening?"
```

- The syntax and the syntax check are the same as for command lines (`@…` lines).
- Use it only to insert an effect while staying on the same page. Effects that can come before or after the page are written as `@` lines.

Inline commands run in order as the characters reach their position. They behave as follows depending on how the player advances.

| How the player advances | Characters | Inline commands |
|---|---|---|
| Reading normally | Appear one at a time | Run where they're written. Commands that wait pause for their duration |
| Clicking while characters are appearing | Everything up to the next `{click}` (or the end of the page if there is none) appears at once, without stopping at ruby or decoration boundaries | Run with the same timing as when reading normally (`{@wait 1s}` waits, and the characters after it appear at once). Clicking again while waiting skips the wait and the effect to the end (chapter 5) |
| Skip | Appear at once | All run, but every duration is 0 (`@wait`, fades, shaking and motion end at once) |

### Moving on without waiting for a click (`{noclick}`)

Write `{noclick}` at the end of a line to move on to the next line as soon as that line has been shown, without waiting for a click (like `{nw}` in Ren'Py).
The text stays in the message window and is cleared by the next text line.

```
Yui "Which way?"{noclick}
@choice
- Take the north road -> #north
- Take the south road -> #south
@end

Ren "Wait—"{noclick}
@quake time=500ms
Ren "...Did it just shake?"
```

- The first example shows the choices while keeping the question on screen. The second inserts an effect while keeping the line on screen, then moves on to the next line.
- It can only be written at the end of a line. In the middle of a line, inside decoration, or in choice text, it's an error (`noclick-not-last`, `noclick-in-option`).
- The text that stays is shown again even when you load a save made while the choices are on screen. `@clear`, `@window hide`, `@nvl` and `@vertical` clear it.
- Auto and skip move on without waiting. A voice that's playing isn't stopped when moving on; whether it stops is decided by the setting in the Settings screen when the next page is shown.
- You don't need to write it in translations (whether to wait is decided by the original).
- When importing from TyranoScript, it's added to a text line that doesn't end with `[p]` and is followed by `[glink]` `[link]` `[button]` `[clickable]` `[s]`.

### Sound during skip and auto

- While skipping, voices (`@voice`, `@voice-auto`) aren't played, and a voice that's playing stops.
  Sound effects (`@se`) play, and BGM changes happen without fading.
- In auto mode, once the page is fully shown (and its voice, if any, has finished), it waits for the auto wait time plus a time based on the number of characters on the page, then advances.

## 4. Vertical writing and NVL

Vertical writing is the traditional Japanese layout, where text runs from top to bottom in columns.

| How to write it | Meaning |
|---|---|
| `@vertical on` / `@vertical off` | Switch to vertical writing, or back to horizontal |
| `ui.message.vertical: true` in liminalia.json | Make the whole game vertical |
| `@nvl on` | NVL (text piles up across the whole screen) |
| `@nvl on style=letter` | Show NVL with a named look from `ui.nvlStyles` in liminalia.json |

In vertical writing:

- Lines advance from right to left, and ruby goes to the right of the characters.
- If the position and size of the message window aren't set, the window is placed on the right of the screen, taller than it is wide.
- In NVL, paragraphs pile up from the right. When they overflow, older paragraphs flow off to the right and disappear (punctuation hanging past the end of a line isn't cut off).
- Balloons (`@balloon`) stay horizontal.

Switching between vertical and horizontal clears the text on screen (the same goes for switching NVL with `@nvl`). Whether the text is vertical is kept in the state, so loading gives the same screen.

**The NVL look, and looks for each scene**

Write the NVL look in `ui.nvl`. For scenes where the text is written on "another sheet," like letters, documents or a terminal screen, write named looks in `ui.nvlStyles`
and switch with `@nvl on style=name`. The text stays ordinary dialogue and narration, so it goes into the backlog, read marks, skipping, voice, translation and the wording checks as usual.

```json
"ui": {
  "nvl": { "background": "rgba(6, 8, 12, 0.72)" },
  "nvlStyles": {
    "letter": { "background": "#efe6d2", "image": "paper/letter.png", "color": "#3a2a1a", "font": "serif", "valign": "top", "padding": [96, 220, 80, 220], "fade": 400, "names": false }
  }
}
```

```
@nvl on style=letter
Dear friend, how are you?
The autumn wind is already blowing here.
@nvl off
```

| Item | Meaning |
|---|---|
| `background` | The background (a color or gradient; dark and translucent by default) |
| `image` | A picture laid over the background (from `image`; cropped to fill the screen, on top of the background color) |
| `padding` | The space around the text (px. One value for all four sides, or four for top, right, bottom, left; 72, 150, 96, 150 by default) |
| `align` | Line alignment (`left`, `center`, `right`) |
| `valign` | Where paragraphs pile up (`top` from the top, `center` in the middle, `bottom` from the bottom, pushing older paragraphs up; `bottom` by default) |
| `font` `color` `size` `lineHeight` | The font (the font the player chose in Settings comes first), text color, size (px; the player's text size is applied) and line height |
| `fade` | A fade when each paragraph appears (milliseconds; none by default. Not while skipping or when redrawing after a load) |
| `names` | Whether to show the speaker's name at the start of a paragraph (`true` by default) |

- A named look is laid over `ui.nvl`, only for the items written. `@nvl on` without `style=` goes back to the `ui.nvl` look. The look's name is kept in the state, so loading gives the same look
- A name that isn't in `ui.nvlStyles` is an error in the syntax check (`unknown-nvl-style`)

Appearance settings:

| Setting | Meaning | Default |
|---|---|---|
| `ui.text.rubySize` | Ruby size (a multiple of the base text) | 0.45 |
| `ui.text.paragraphGap` | Space between NVL paragraphs (a multiple of the text size) | 0.5 |
| `ui.text.emphasis` | Shape of emphasis dots (CSS `text-emphasis-style`) | `filled sesame` |
| `ui.text.quotes` | The outer brackets and quotation marks of dialogue. `keep` shows them as written. `strip` removes the outer pair (`「…」` `『…』` `“…”` `"…"`) and shows only what's inside (below) | `keep` |

How `ui.text.quotes: "strip"` removes them:

- They're removed only when the first character of the text is an opening mark and its matching closing mark is the last character. Text that closes partway through, such as `「あ」「い」` or `"a" and "b"`, text that isn't closed, and text with ruby or `{= expression}` at either end are left as they are.
- `（…）` and `(…)` stay, because they mark inner thoughts. Nested brackets (the `『』` in `「『夢』だった」`) stay too.
- If there's a translation, they're removed from the translated text. It works the same in the message window, NVL, the backlog, `@balloon` balloons and regular dialogue on the chat screen.
- The chat screen removes `「…」` and `『…』` even with `keep` (the speech bubble takes the place of the brackets).
- You can set it per language (`ui.languages.en.text.quotes`; for example, show brackets in the Japanese original and remove quotation marks in the English translation). It stays when you switch themes.

## 5. Writing commands

```
@command unnamed… name=value …
```

Command names are lowercase letters, digits and `-`.

### Value types

| How to write it | Type |
|---|---|
| `300ms` `1.5s` | Duration. The unit is required (`300` alone is an error) |
| `3` `-0.5` | Number |
| `true` `false` | Boolean |
| `#000` `#cc3333` `#cc333380` | Color |
| `"a string with spaces"` | String |
| `room_night.jpg` `Yuika` | String (without spaces) |
| `(expression)` | Expression, evaluated at run time (`@wait (time)`, `at=(temp.pos)`) |
| `#label` `file` `file#label` | Jump target (`@sleep-game extra#gallery`). The syntax check confirms that the label and file exist |
| `game.x` `system.x` `temp.x` | Variable. Receives a command's result (`@text-input game.name`) |

### Parameter rules

To set a named boolean parameter to `true`, you can write just its name, as in `@chara Yuika solo` (the same as `solo=true`). To set it to `false`, write `solo=false`. When a line is read, the first unnamed parameter and any required unnamed parameters are filled first. If a word written as just a name could also be read as the value of an unnamed parameter that isn't filled yet, the syntax check reports an `ambiguous-bool-shorthand` error. If you meant the boolean, write `solo=true` in full. Clashes that depend on the project's definitions, such as variant names, are found when those definitions are available. To give only a boolean while leaving out the first unnamed parameter, write it as `wait=true`.

- **Don't write values that equal the default.** This is a writing rule, and the syntax check doesn't treat it as an error. A value equal to the project default (`commandDefaults`)
  gets left behind when the default changes, so the check reports it as info (`same-as-default`) with a fix that removes it (Fix all in Studio removes them at once).
- **Unnamed parameters can't be written with a name** (`positional-by-name`). Which parameters are unnamed is decided for each command.
- In a command with two unnamed parameters, the two always have different types (in `@chara Yuika smile`, a character and a variant).
  If you put them in the wrong order, the syntax check catches it.

### Scene change (`@scene-change`)

`@scene-change background time=1500ms` fades out (`@mask`) → hides all sprites (`@chara-hide-all`) → changes the background (`@bg`) → fades back in (`@mask-off`), all in one command.
Set the fade-out and fade-in time with `time` (or separately with `fade-out` and `fade-in`), the time to stay covered with `hold`, and the fade color with `color`. If you omit the background, it only hides the sprites.
By default, the message window is hidden as soon as the fade-out starts and shown again with the next text (so the previous text isn't seen during the fade in; `hide-window=false` keeps it shown).
The hidden previous text isn't shown again, so even if `@window show` right after brings the window back, it's empty, and in NVL the next text starts on a new page (the same goes for `@mask` and `@bg hide-window=true`).

```
@scene-change backgrounds/street_night.png time=1500ms hold=100ms
@scene-change time=1000ms hold=500ms hide-chara-at=start hide-fade=300ms
@scene-change time=1000ms hide-who=Yuika hide-chara-at=start hide-fade=300ms
@scene-change hide-chara=false hide-window=false
@scene-change backgrounds/office.png stop-bgm=true bgm-fade=300ms
@scene-change backgrounds/beach.png bgm=summer.ogg
@scene-change bg-color=#000000 time=800ms
```

- For a solid background, write a color instead of a picture (`@bg color=#000000`, `@scene-change bg-color=#ffffff`). You don't need a black or white image, and saves keep it as a color (load and rewind bring back the same color).
  Don't write a picture and a color together (`redundant-param`). `@bg` needs one of them (`missing-param`).

- With `hide-chara-at=start`, the sprites start to disappear as soon as the fade-out starts. If it's omitted (`covered`), they start once the screen is fully covered. `hide-fade` is the time the sprites take to disappear, separate from the fade-out and fade-in time (`time`). `hide-who=Yuika` hides only that character; without it, everyone is hidden. `hide-chara=false` keeps everyone. It doesn't wait for the sprites to finish disappearing; that runs alongside the fade-out and fade-in. The old name `hide-at` still works, but don't write both.
- By default, the message window and the quick menu buttons are hidden as soon as the fade-out starts. `hide-window-at=covered` hides them once the screen is fully covered, and `hide-window=false` doesn't hide them.

- To stop the BGM behind the fade, write `stop-bgm=true`; to change it, `bgm=track` (looping; the volume is `bgm-volume`, default 100). Both start once the screen is covered and fade over the `bgm-fade` time (default 0ms).
  Writing `bgm` replaces the current track, so don't write it together with `stop-bgm` (`redundant-param`). To set the volume or loop points, write a separate `@bgm`.

- The state (save, rewind, load) is how things look after the fade in; what happens in between isn't kept. While skipping, it takes no time.
- Where the screen is already fully faded out (such as at the top of a file reached by `@jump` after `@mask` at the end of the previous file), it doesn't wait for the fade-out time (`time` or `fade-out`); it hides the sprites, changes the background, and fades in.
- If the background image is a CG in the extras, it's unlocked (same as `@bg`).
- It isn't named `scene` so that it doesn't clash with scene-change macros that projects wrote themselves (such as `@define scene` in the earlier template) (existing project macros keep working too).
  The current template uses `@scene-change`, with the fade time set in `commandDefaults` (below).
- A fade time for the whole project can be set in `scene-change` in `commandDefaults` (below) (`"scene-change": { "time": "1500ms", "hold": "100ms" }`).
- `lim backport` writes it back as the sequence `[mask]` `[chara_hide_all]` `[bg]` `[mask_off]` in .ks (`hold` becomes the `time` of `[bg]`, or `[wait]` when the background is omitted; BGM becomes `[stopbgm]` or `[playbgm]` right after `[mask]`).

### Scene breaks

Things that shouldn't interrupt the middle of a conversation or the moment right after an emotional peak, such as notifications (`@notify when=scene-break`), are held and shown at a scene break.
A scene break is the point where the running game has passed one of the following.

| Break | What it covers |
|---|---|
| `@scene-change` | Including one without a background (one that only hides the sprites) |
| Changing the background | When `@bg` shows a picture different from the current one (showing the same picture again isn't a break). Also when a plugin command changes the background |
| Fade to black | `@mask` |
| Changing files | When `@jump` or a choice (including `default` when time runs out) moves to another file. Chapters (`chapters`) are groups of files, so chapter breaks are included here. `@call` and `@return`, and moves by plugin commands (`ctx.runtime.jump`, `callScene`), aren't breaks |

```
Sou "...Found it."
@notify "A new page was added to the notebook" kind=success when=scene-break
Akari "What is it, all of a sudden?"
@scene-change hill_night.webp
// ↑ After the fade in, the notification appears before the next text
```

- What's held is shown after the break has been passed, before the first text or choice is shown (not during the fade out or fade in). Something held after a break waits until the next break.
- What's waiting is kept in the save (`stage.sceneWait`). It isn't lost when you save and load while it's waiting, and it isn't in saves of pages after it was shown, so loading doesn't show it twice.
  The same goes for the states kept by rewind and `@sleep-game`.
- If the playthrough ends without passing a break (`@title-screen` and so on), what was waiting isn't shown.
- Plugin commands can hold things the same way with `ctx.atSceneBreak(args)` (instead of `ctx.present`) ([docs/plugins.md](../plugins.md)).

### Project command defaults (commandDefaults)

Write command name → parameter name → value (in .lim syntax: `"400ms"`, `"true"`, `"default"`) in `commandDefaults` in `liminalia.json`,
and that value is used for parameters omitted in the scenario. It applies to both built-in and plugin commands.

```json
"commandDefaults": { "chara": { "time": "400ms", "appearance": "default" }, "bg": { "time": "1s" } }
```

- A parameter you write always uses that value; writing `time=0ms`, for example, takes priority over the default.
- You can set them for `@define` macros too (`"scene": { "time": "1500ms" }`). Only parameters that have a default can be set (parameters without one are required, so they can't be). Values are checked against the type (`duration` and so on).
- If you set a default for a parameter that "keeps the current value when omitted" (`appearance`, `at` and others of `@chara`), that value is used when it's omitted too (the current value isn't kept).
- Changing the default of `wait` also changes whether that command waits for its effect to finish (in Studio's timeline too).
- Unknown commands, unknown parameters, required parameters, expressions and type errors are reported by the syntax check as `liminalia.json` errors (`bad-command-defaults`), and those values aren't used.
  Sprite sets, variants and positions that aren't written in the scenario are checked against the character definitions as values set by the defaults.
- `lim reference <project>`, completion and the parameter panel in Studio, and completion in VS Code show these values as the defaults (`lim reference` also shows the standard default).
  In Studio, you can edit them in "Command defaults" in "Game settings" (they're saved right away, and the preview runs with the new defaults from the next "New Game" or load).
- `lim backport` writes the defaults into omitted parameters before writing back to .ks (values set by the defaults are written into the .ks tags, so TyranoScript behaves the same; macro calls too).

### Waiting for effects

The default of `wait` depends on the kind of command. If you write `wait=`, that takes priority.

| Kind | Default | Commands |
|---|---|---|
| Building the scene (backgrounds, images, the whole screen, camera, shaking, movement) | Waits | `@bg` `@scene-change` `@image` `@free-image` `@transition` `@mask` `@blend` `@camera` `@quake` `@chara-move` and others |
| Showing and hiding sprites, expressions | Doesn't wait | `@chara` `@chara-hide` `@chara-hide-all` |
| Repeating motion, overlaid video | Doesn't wait | `@anim` `@kanim` `@blend-movie` |
| Sound | Doesn't wait | `@bgm` `@se` `@voice` (to wait, use `@wait-bgm` `@wait-se` `@wait-voice`) |

Sprites usually change together with the dialogue, so they don't wait. Changes to the background or the whole screen finish before the text appears.
The default for each command is under `wait` of that command in [commands.md](../commands.md) (commands that wait but have no `wait` say that they wait until they finish).

### Skipping effects with a click

While the game waits for an effect that takes time, a click (or the Enter key, or a tap) by the player skips the running effect to its end state.

- What can be skipped: background and sprite changes, fading to black (`@mask`), the camera, shaking, rule transitions, color tone and depth of field, the wait of `@wait`, and the effects of project commands (commands that have a time parameter and wait for their end).
  Until that command finishes drawing, motions that start after it (such as the second half of a sprite change that disappears and then reappears) also end at once. Other effects running without waiting (sprites with `wait=false` and so on) end along with it.
- What can't be skipped: sound (it keeps playing), repeating motion, choices on screen, commands that wait for sound such as `@wait-bgm`, and screens waiting for input.
- One click skips only the effect being waited for at that moment. Click again for the next effect.
- For a command that shouldn't be skipped, write `skip=false` (the same name as `skip` of `@movie`; `@movie` isn't skippable by default). To turn it off for the whole game, set `ui.input.skipEffects: false` in liminalia.json.
- `@movie` can be skipped with a click even with `skip=false` if the movie has been watched to the end once (the variable `movies_watched`, shared by all saves), the same idea as read text.
  To exclude a single movie, write `skip-seen=false`; to exclude them in the whole game, write `"skip-seen": "false"` under `movie` in `commandDefaults`.
- A skippable `@movie` (`skip=true`, or a watched movie as above) ends with a click (the confirm key or a tap), doesn't play while skipping, and ends if skipping starts while it plays.
  A `@movie` that can't be skipped plays even while skipping (the same as TyranoScript). To make movies skippable in the whole game, write `"skip": "true"` under `movie` in `commandDefaults`.
  During the development fast-forward (`?skip=N`) and automated checks (`lim playtest`, `lim shot`), even movies that can't be skipped don't play.
- While skipping, effect durations are 0 even if you don't write anything (chapter 3).

### Screen effect shaders

Among the kinds of `@effect`, `radial-blur` (rotational blur), `zoom-blur`, `mosaic`, `ripple` and `shader` use WebGL.

- Every frame, the picture of the target (the whole screen or a layer) is copied, run through the shader, and shown on top.
- Only position, size, opacity, CSS filters and sprite flipping are copied; transforms such as rotation aren't.
- If you apply two to the same target, only the later one is visible.

`shader` takes a fragment shader from the project (GLSL ES 1.0; a path from the `others` folder). The shader receives the following (declarations are added if you haven't written them).

| uniform / varying | Contents |
|---|---|
| `u_texture` | The copied picture |
| `v_uv` | 0 to 1. The bottom left is 0 |
| `u_resolution` | Size (px) |
| `u_time` | Seconds, multiplied by `speed` |
| `u_strength` | The value of `strength=` |
| `u_center` | The values of `x=` `y=` (0 to 1) |

Values written as `values="glow=0.5 tint=0.2"` are received with `uniform float glow;` and so on.

### Fading filters and screen effects, and limiting them to an area

`@filter` and `@filter-off` fade over the time in `time=`, and `@effect` and `@effect-off` over the time in `fade=` (`@filter` moves from the previous filter; `@effect` raises its strength from 0, or lowers it to 0).
By default the script continues without waiting; write `wait=true` to wait until it finishes. While skipping, it takes no time. The state (save, rewind, load) is how things look after the fade.

`mask="radial x y width height"` (with a soft edge, `"radial x y width height soft"`; all in px) applies it only inside the ellipse. `radial-out` applies it outside the ellipse.

```
@filter grayscale=100 mask="radial-out 640 360 520 400 80" time=600ms
@effect mosaic strength=24 mask="radial 900 300 240 240" fade=300ms
@effect-off mosaic fade=300ms
```

- A `@filter` with a mask applies, inside the area, to the background for `base`, the background and sprites for `fg0`, and everything up to the foreground for `fg1`, `fg2` and `all` (it filters what's behind it).
- The mask of `@effect` works for the overlay kinds (`noise`, `vignette`, `scanlines`) and the WebGL kinds. `wave`, `glitch` and `chromatic` can't be limited and apply to everything.
- A `@filter` with a mask uses CSS that filters what's behind it (`backdrop-filter`). Browsers without it (Firefox up to 102) don't show it and report it in the developer tools (a `@filter` without a mask still shows).
- The syntax check reports a `mask=` it can't read (`bad-effect-mask`). It also warns about `mask=` on `wave`, `glitch` and `chromatic` (`effect-mask-ignored`).

### HUD buttons and text (`@hud-button`, `@hud-text`)

Buttons and text that stay on screen while playing. Both are placed by name; writing the same name again replaces it, and `@hud-button-off` and `@hud-text-off` remove them (all of them if the name is omitted).
They're kept in saves and show up the same after load, rewind and skipping. They're hidden while the player hides the message window ("Hide"; `@window hide` doesn't hide them).
They sit above the message window and below the blackout, so they darken with the `@mask` and `@scene-change` blackouts, and they're hidden (and can't be pressed) while the screen is fully blacked out, during chapter cards (`@chapter-card`, `@chapter-end`) and during full-screen movies.

```
@set game.day = 1
@hud-text day text="Day {= game.day}" x=40 y=24 size=28
@hud-button memo image=ui/memo.png hover=ui/memo_on.png x=1180 y=20 call=#memo key=m show-if=(game.has_memo)
```

- `{= expression}` in `@hud-text` is redrawn whenever a variable changes.
- Pressing a `@hud-button` calls the `call=` scene. The scene returns at `@return` or the next label, and the page being read is shown again (the backlog and `temp.` variables from before the call carry over as they are).
  It can be pressed while a page waits for a click and while choices are shown. Pressed during choices, the choices are shown again when the scene returns (a timed choice starts its timer over).
- It can also be pressed with a keyboard or a gamepad. While playing, up and down on the arrow keys and the D-pad select a HUD button, and the key that advances the text (Enter and so on) or A on a gamepad presses it.
  Esc or B on a gamepad stops selecting. Left and right on the D-pad still quick save and quick load while nothing is selected. If the game or the player has assigned the arrow keys to other actions, the arrow keys do those instead.
- With `key=`, that key presses it (`key=m`; upper and lower case letters are treated the same, and key names such as `F1` work too). It works while playing and while choices are shown,
  and comes before the default keys of other actions (with `key=m`, m presses this button instead of muting). Buttons with a key are also listed on the Controls screen.
- `show-if=(expression)` is the condition for showing it. It's hidden while false and checked again whenever a variable changes.
- The text of `@hud-text` and of text-only buttons gets larger with the player's text size setting (not in games where `ui.screen.textScale` is `message`).
- `text=` of `@hud-text` and `label=` of `@hud-button` written as literal text are shown again in the new language when the language changes.
- The project's CSS can restyle `.lim-hud-button` and `.lim-hud-text` (the name is in `data-hud`).
- TyranoScript's `[button fix=true]` is imported as `@hud-button`, and `[clearfix]` as `@hud-button-off`.
- If no `@hud-text` or `@hud-button` shows the name given to `@hud-text-off` or `@hud-button-off`, the syntax check warns (`hide-name-unknown`; the same for `@cutin-hide`).

### Manga symbols and manga-style effects (`@emote`, `@speedlines`, `@burst`, hit stop, a camera that goes and comes back)

`@emote character kind` attaches a manga symbol to a sprite on screen (`sweat`, `anger`, `surprise`, `question`, `heart`, `sparkle`, `music`, or `image` for the project's own `image=`).
`at=` is `head` (above the head), `head-left`, `head-right` (beside the head; left and right as seen on screen) or `face`; if omitted, the usual place for the kind. The head is found from the sprite's picture
(the same measurement as aligning head sizes). Offsets are `x=` and `y=`, and the size is `size=`.

```
@chara Akari surprised
@emote Akari sweat
Akari "Huh..."
@emote-off Akari
```

- The symbol moves with the sprite (moving, swaying, `@anim`), stays when the expression changes, and goes away when the sprite is hidden (it doesn't come back when the sprite is shown again). It's part of the sprite's state, so saves, load, rewind and skipping show the same.
- With `time=`, it shows for that long and disappears as a one-shot effect (not kept in the state).

One-shot manga-style effects (not kept in the state; a click fast-forwards them, and they don't show while skipping):

| Written as | What it does |
|---|---|
| `@speedlines focus x=640 y=300` | Focus lines (converging on the center). `flow dir=left` streams speed lines one way. Amount is `density`, color is `color`, length is `time` |
| `@burst text=BAM!` | Pops up a jagged impact burst and fades it out, optionally with a sound effect. Position is `x` and `y`, size is `size` |
| `@flash white hitstop=120ms zoom=1.03` | Once a frame is shown, freezes motion on screen (sprite sway, animations, screen effects) for a moment (hit stop), zooms in, then comes back. Flashing more than 3 times a second can cause seizures, so the syntax check warns (`flash-rate`) |
| `@camera zoom=1.2 yoyo=true time=600ms` | Moves to the given view in half the time and back to the previous view in the rest. The camera's state doesn't change |

### Cut-ins that stay (`@cutin stay=true`)

`@cutin` is a one-shot effect that slides in a framed image, holds it, and pulls it out. With `stay=true` it stays after sliding in, and `@cutin-hide` pulls it out.
It's kept in saves and shows up in the same place after load, rewind and skipping. With a name (`name=`), showing another one with the same name replaces it, and `@cutin-hide name` pulls out only that one.

```
@cutin props/key.png stay=true name=key max-width=520 max-height=347 padding=18 from=none
……
@cutin-hide key
```

- The size is `width` and `height`. Without them, the image is shrunk to fit `max-width` and `max-height` (including the frame and padding), keeping its aspect ratio; without those too, it's the image's size.
- `padding` is the space between the image and the frame (filled with the frame color). The project's CSS can restyle the frame with `.lim-cutin-frame--stay` (the name is in `data-cutin`).
- With `hide-window=true`, the message window is hidden only while it slides in (with `@cutin-hide`, while it's pulled out).
- Like HUD items, cut-ins that stay go above the message window and below the blackout (`layer=hud`). They're hidden while the screen is fully blacked out and during chapter cards, and come back afterwards.
  To keep one above the blackout too, write `layer=overlay` (one-shot `@cutin` has always defaulted to `overlay`).

### HTML without JS (`@html`)

For displays that are hard to build by combining commands, such as cards, tables, status screens and buttons that jump when pressed, write HTML between `@html` and `@end`.

```
@html notice x=100 y=80 width=600 time=300ms wait=true
<div class="card">Day {= game.day}</div>
<button data-jump="town#market">To the market</button>
<button data-jump="#home">Go home</button>
@end
@html-hide notice time=300ms
```

Write parameters on the `@html` line just as for a command. From the next line up to the line with only `@end`, the content is kept as is without applying the line rules (same as `@script`).

**Placing and removing**

- It's placed at `x` `y` (px) on a foreground layer (`layer=`; default `fg2`). If `width` `height` are omitted, it takes the size of its content.
- An `@html` with the same name (the unnamed parameter) replaces the earlier one.
- `@html-hide name` removes it. If the name is omitted, everything placed with `@html` is removed. `@free-image` also removes it.

**Embedding values**

- `{= expression}` is evaluated when shown and embedded as text that isn't read as HTML. The expression and its syntax check are the same as `{= expression}` in text.
- The evaluated HTML is kept in the save, so loading rebuilds the same display.

**Buttons (`data-jump`)**

- Write a jump target (`#label`, `file`, `file#label`) in `data-jump`. The syntax check confirms that the target exists.
- **Only an `@html` with `wait=true` can be pressed.** It doesn't move on until a button is pressed, then jumps there (like a choice; a save made while waiting resumes from this `@html`).
- `data-jump` in an `@html` without `wait=true` is display only and can't be pressed (warning `html-jump-without-wait`).
- An `@html` with `wait=true` but no `data-jump` element only waits until it has been shown.
- When running without a screen (route exploration, the all-routes test, `lim trace`), `data-jump` elements are offered as choices.

**Images**

- In `src`, write an asset in the project's `image` folder (same as `{img …}` in text). The syntax check and `lim build` count it as an asset reference.

**What you can write**

- Tags: `div` `span` `p` `br` `hr` `strong` `em` `b` `i` `u` `s` `small` `ruby` `rt` `rp` `img` `ul` `ol` `li` `table` `thead` `tbody` `tr` `td` `th` `h1` to `h4` `button`
- Attributes: `class` `style` `src` `alt` `width` `height` `title` `data-jump`
- Style it with the `style` attribute or with a `class` from the project's CSS.

**What you can't write (syntax check errors)**

- `<script>`, `<style>`, `<iframe>`, `on…` attributes, `javascript:`
- External URLs (in `src` and in `url()` in `style`)
- `{= expression}` in `src` and `data-jump` (so that jump targets and assets can be checked in advance)
- Badly nested or unclosed tags

JS isn't allowed because it can't be checked before running and can change the screen in ways that aren't kept in the save (loading wouldn't restore it).

### Staff roll (`@staff-roll`)

Text that scrolls from bottom to top. Write the content between the `@staff-roll` line and the `@end` line, or point `file=` to a JSON file in the `data` folder (an array of strings written the same way as the content). With `file=`, `@end` isn't needed.

```
@staff-roll time=90s bg=#000000
# Scenario
Yui

# Music
Ren
{img logo.png 120}
@end

@staff-roll file=credits time=90s
```

| Content line | Meaning |
|---|---|
| `# Heading` | Heading (a role and so on) |
| Empty line | Adds space |
| A line with only `{img path}` `{img path height}` | Image (`image` folder; height in px). The syntax check confirms that the asset exists |
| Anything else | Shown as is, for names and other text (to show `#` at the start of a line, write `\#`) |

- It finishes scrolling in `time` (default 60s) and doesn't move on until it finishes. A click skips to the end (not with `skip=false`). It isn't shown while skipping.
- Change the look with the project's CSS (`.lim-staffroll` `.lim-staffroll-heading` `.lim-staffroll-line` `.lim-staffroll-gap` `.lim-staffroll-image`).
- It isn't kept in the state. A `@staff-roll` with no content is a warning (`staff-roll-empty`). TyranoScript has no equivalent, so `lim backport` reports it as something it can't write back.

### The end of a playthrough (`@title-screen`)

`@title-screen` ends the playthrough and returns to the title. With the kind of ending in `ending=`, the screen fades to black and shows the kind's wording (BAD END for `bad`) and an end mark
(`text=`; the Japanese mark for "the end" if omitted, The End when playing in English), and waits for the player to press (click, tap, Enter, Esc, right-click or A on a gamepad) before returning to the title.
With a name for that ending only in `title=`, the name is shown large with the kind's wording small above it. The kind and name also appear in the endings list in Extras and in the Studio flowchart.

```
@title-screen ending=bad
@title-screen ending=bad title="Silence"
@title-screen ending=other title="Passing Shower"
@title-screen ending=true text="Fin"
```

- `ending=` is a kind, not wording. The wording on screen comes from the kind. Avoiding endings in recordings and `lim playtest` (`--avoid-ending bad`), counting in `lim coverage`,
  `expect ending` in script tests, achievements (`endings` in `extra.achievements`) and `endings()` in expressions all go by the kind too, so changing or translating the wording doesn't affect them.
- `title=` is translated text (the "command text" of translation files). Leave it out if the ending has no name.

| Kind | Default wording (Japanese and English) |
|---|---|
| `bad` | BAD END |
| `normal` | NORMAL END |
| `good` | GOOD END |
| `true` | TRUE END |
| `other` | None (only the name in `title=` is shown; the catch-all for endings that fit no kind) |

- Add kinds with `endingKinds` in `liminalia.json` (`"endingKinds": { "secret": "SECRET END" }`; names start with a lowercase letter and use lowercase letters, digits, `-` and `_`).
  Listing a built-in kind gives it the project's own wording (`"bad": "Bad Ending"`). The wording in `endingKinds` is translated as project settings text (multilingual, chapter 10).
- The wording of built-in kinds can also be changed in the project's text tables: `ending.kinds.bad` and so on in `ui` of a translation file (for languages other than Japanese and English, `lim i18n` lists them with the English source),
  and `texts` of a plugin ([plugins.md](../plugins.md); this also changes the source language's wording). For kinds written in `endingKinds`, the `endingKinds` wording comes first.
- An unknown kind is an error (`unknown-ending-kind`; the suggested fix is the closest kind name). `ending=true` is the kind `true`, not a boolean.
- In projects with script format 2 or earlier, the earlier way of writing wording in `ending=` (`ending="BAD END"`, `ending="Passing Shower"`) keeps working until it's migrated, and the screen shows the wording as written.
  Wording that tells the kind (BAD END, GOOD END, TRUE END, NORMAL END and their variants) counts as that kind; other wording counts as `other` with the wording as its name.
  The syntax check warns (`legacy-ending`) with the current way of writing as the suggested fix, and `lim migrate` moves the whole project ("Script format versions" in chapter 10).
- With `card=false`, it returns right away without showing the name (as in earlier versions). To turn it off for the whole project, write `"commandDefaults": { "title-screen": { "card": "false" } }`.
- During auto, it's shown for 4 seconds and then moves on. It isn't shown in automated checks (`lim shot`, `lim playtest`). Recordings (`lim shot --video`) show it and then move on.
- The look follows the theme's colors and font (`titleBg`, `fg` and `accent` in `ui.system`, and the text font), and the project's CSS can override `.lm-ending` (`.lm-ending-kind`, `.lm-ending-name`,
  `.lm-ending-rule`, `.lm-ending-mark`). The kind is in `data-kind` of `.lm-ending` (to style a kind, use `.lm-ending[data-kind="bad"]`).
  To replace it entirely, use a plugin's `screens.ending` ([plugins.md](../plugins.md)).
- For the end of a chapter, use `@chapter-end` (it keeps the blackout and moves on). To roll the credits at the end of the game, write `@title-screen` after `@staff-roll`.

### JS kept until it's rewritten (`@script`)

The content between `@script` and `@end`, up to the line with only `@end`, is kept as is without applying the line rules. It's a place to keep JS from `[iscript]` imported from TyranoScript (code that uses jQuery or `TYRANO`)
until you rewrite it as plugin commands, and **its contents don't run in any environment (test play, the exported game, or running without a screen)**.

- **It can only be written in projects whose liminalia.json has `"allowScript": true`.** Otherwise it's a syntax check error (`script-not-allowed`).
  Even then, the syntax check warns on each `@script` line that its contents don't run (`script-skipped`). The same warning is given when the game passes it while running, and it moves on to the next line.
- It doesn't run because the exported game doesn't allow `eval` (the CSP's `script-src 'self'`), and because imported JS assumes TyranoScript's internals (jQuery, `TYRANO`, `mp`),
  so it can't run as is.
- Make logic and effects specific to your game as plugin commands (`@liminalia/sdk`). To build a display, use `@html`. Remove `@script` once it's rewritten.
- `lim backport` turns `@script` back into `[iscript]` … `[endscript]`.

## 6. Sprites

```
@chara Yuika normal at=left time=500ms
@chara Yuika smile time=300ms
@chara Yuika normal appearance=casual at=center flip=true
@chara Ren angry at=auto if-hidden=true
@chara Haru normal x=120 y=40
@chara-hide Yuika time=300ms
```

Sprites work the same way as the sprite plugin Tyrano Tatie (tatie). They're defined in three levels in cast.json (chapter 10), and the scenario refers to them by name.

| Level | Parameter | Example |
|---|---|---|
| Character | Unnamed (the first) | `Yuika` |
| Sprite set (outfit, era, condition and so on) | `appearance=` | `casual` |
| Variant (expression, pose). Has an image, and a position and size (`frame`) | Unnamed (the second) | `smile` |

### Showing and changing

- **`@chara` both shows and changes a sprite.** If the character isn't on screen, it fades in; if it is, the sprite changes.
- `if-hidden=true` shows it only when it isn't on screen (if it's on screen, nothing happens; `mode=show` in tatie).

### Automatic layout by order of appearance

To use automatic layout by order of appearance in the whole game, set `"auto-layout": true` in `commandDefaults.chara` in `liminalia.json`. A newly shown character without `at` is placed in the center when alone. Two are placed left and right in the order they appeared, three left, center and right, and more are lined up from the left in the order they appeared. Changing the expression doesn't change the order. A character with an explicit `at`, `x` or `y` keeps that position. The older `at=auto` remains as a separate way of placing characters.

When the number of characters in the automatic layout changes, the characters on screen fade out, are rearranged, and fade back in. The time to hide them is `auto-fade` (default `300ms`), and the time to show them is `time`. With `wait=true`, it waits until the rearranging is done.

The automatic layout is kept in saves. In a save made before the setting was turned on, characters already on screen are restored fixed in their original positions. They join the automatic layout only after they leave and are shown again without a position.

You can change how characters are lined up for each game with `autoLayout` in `liminalia.json`. Each character's home side goes in `side` for that character in cast.json.

```json
"autoLayout": {
  "positions": {
    "2": ["left", "center"],
    "4": ["15%", "38%", "62%", "85%"]
  },
  "enter": "start",
  "exit": "keep"
}
```

```json
"Yuika": { "side": "left", "appearances": { … } }
```

| Item | Meaning |
|---|---|
| `positions` | Positions for each number of characters. Use the number as the key and list the positions from the left. A position is a name from `positions` in the sprite frame, or a fraction of the screen width (`"30%"`; the center of the sprite goes there). Numbers you don't write use the default layout above |
| `enter` | Where a newly arriving character goes. `end` is the right end (default), `start` the left end, `middle` the middle |
| `exit` | What happens when someone leaves. `reflow` (default) lines up the remaining characters again. `keep` leaves the slot empty without moving anyone, and the next character to arrive takes that slot. A character who arrives when there's no empty slot makes the row one longer, and everyone is lined up again |
| `side` (cast.json) | The character's home side. `left` keeps them at the left end of the row and `right` at the right end. Characters on the same side keep their order in the row. When taking an empty slot with `keep`, they take the one closest to that side |

- The order of the row is kept in saves, so loading brings back the same row.
- `replace=` also accepts the position names written in `positions`.
- The syntax check reports an error (`bad-auto-layout`) when the number of positions doesn't match the number of characters in `positions`, when `enter` or `exit` has an unknown value, and when a position name isn't in any sprite frame.
- When a rule's position name isn't in that character's sprite frame, it's also reported at runtime (`unknown-position`; the sprite is shown at the center). This covers not only the character being shown but also the others who moved when the lineup changed.
- Sprites placed by a position name (`at=left` and so on) can be remapped to another position by headcount with `byCount`. Key it by headcount and map each written position name to the position to use. The remap applies only while exactly that many sprites are on screen; when the headcount changes, the sprites move to their new positions the same way as any position change. Sprites whose frame lacks the target position, sprites with `x`, and auto-layout characters aren't remapped.

```json
"autoLayout": { "byCount": { "3": { "left": "left-wide", "right": "right-wide" } } }
```

- The syntax check also reports an error (`bad-auto-layout`) when a `byCount` key isn't a headcount, when a name is empty, or when a target position isn't in any sprite frame. The same goes for a written name (the name you write in `at=`) that isn't in any sprite frame (you can't write it in `at=`, so the mapping never applies).
- The syntax check reports an error (`bad-cast`) when `side` in cast.json is anything but `left` or `right` (it would be ignored, and the character placed in order of entrance).
- `replace=` accepts the remapped position name from `byCount` (the name shown in Studio's scene info) as well as the written one.
- During development, changes to `autoLayout` or `side` take effect without reloading the game. Sprites on screen move to their positions under the new rules. Studio's scene information and VS Code's "Play from here" use the same rules.

### Replacing a character

`@chara Mayu oops replace=Tsuzuri time=500ms` hides Tsuzuri and shows Mayu, taking over Tsuzuri's position and place in the order of appearance. The other characters stay on screen without moving. `replace=left`, `center` or `right` replaces the character at that position. A name in the sprite frame's `positions`, a name written in `autoLayout`'s `positions`, and the name after `byCount` remaps it also work (choose a character placed with `x` or `y` by name). `left`, `center`, `right` and the names in `autoLayout`'s `positions` are treated as positions even if a character has the same name. For other position names, a character with the same name comes first.

When there's no one to replace, when there's more than one character at that position, or when the character to show is already on screen, an error is reported at run time and nothing changes. Don't use `replace` together with `at`, `x`, `y`, `clear` or `solo`. `time` is both the time to hide the character leaving and the time to show the character coming in.

**Entering and leaving, sliding to a new position, one character at a time, stacking order**

```
@chara Yuika smile time=500ms enter=left
@chara Yuika at=right time=600ms slide=true
@chara Ren time=300ms solo=true
@chara Yuika at=left clear=300ms time=500ms
@chara Haru z=2
@chara-hide Yuika time=400ms exit=bottom
```

| Parameter | Meaning |
|---|---|
| `enter` (`@chara`), `exit` (`@chara-hide` `@chara-hide-all`) | How it appears and leaves. `fade` (default; in place), `left` `right` `top` `bottom` (slides in from that side or out to that side, by `distance` px; default 160), `zoom` (from a small size, or to a small size). The time is `time`. `enter` only applies when the character wasn't on screen |
| `slide=true` | When the position of a character on screen changes, slide it over the `time` time instead of hiding and showing it again (if the image changes too, it cross-fades while sliding) |
| `solo=true` | Hide the other characters' sprites over the `time` time before showing. In a game that always shows one character at a time, write `"solo": "true"` under `chara` in `commandDefaults` |
| `clear=300ms` | Hide everyone, including the character themselves, over the given time, and show the new sprite. It works like `@chara-hide-all time=300ms` followed right away by `@chara` in one line, and doesn't wait for the hiding to finish. The time to show is set separately with `time` |
| `z` | Stacking order. Higher values are in front; with equal values, the one shown later is in front (default 0). If not written, a character on screen keeps its current order |

- Only `z` is kept in the state (how a sprite enters, leaves or slides isn't).
- `lim backport` writes `solo=true` back as two lines, `@chara-hide-all` (with the same `time`) and `@chara` (in .ks, the character also disappears once and reappears).
- `clear` is also written back as two lines, `@chara-hide-all` with the written time, and `@chara`.
  `enter` `exit` `slide` `z` aren't in TyranoScript's sprite tags, so they're reported as things it can't write back.

What you don't write is decided as follows.

| | Variant, sprite set and flip not written | Position not written (none of `at` `x` `y`) |
|---|---|---|
| Character on screen | Stays as is | Stays as is. If you write any of them, it's placed again by what you wrote |
| Character not on screen | Base variant, default sprite set, not flipped | `center` |

To change only the expression, `@chara Yuika smile` is enough.

When a sprite on screen is replaced, it changes as follows, depending on what differs from before.

| Image | Position and size (`frame`) | How it changes |
|---|---|---|
| Same | Same | At once (only the flip changes) |
| Same | Different | Disappears in half of `time`, changes position and size, and appears in the rest |
| Different | Same | Cross-fades only the image. With `cross=false`, the new image is shown fully before the old one is removed |
| Different | Different | Cross-fades the whole sprite |

If the next `@chara` comes in the middle of a change, the change in progress jumps to its end state before the next one starts.

### Reducing flicker

Hiding a sprite and showing it again every time the speaker changes makes the screen flicker, and only one of the characters in the scene is ever standing.
Keep the characters in the scene standing, change only their expressions with `@chara name variant`, and show who is speaking with speaker focus.

```json
"ui": { "chara": { "focus": "dim-lower", "dim": 0.7, "lower": 10 } }
```

| Mechanism | How to write it | What it does |
|---|---|---|
| Speaker focus | `ui.chara` in liminalia.json, `@chara-config` in the script | Tones down the sprites of characters who aren't speaking. `focus` is `dim` (darker), `lower` (a little lower), `dim-lower` (darker and lower), `blur` (blurred), `dim-blur` (darker and blurred) or `none` (unchanged; the default). The strengths are `dim` (brightness 0 to 1; default 0.6) and `lower` (px; default 12) |
| Replacing at the same position | `swap` of `@chara` | When another character's sprite at the destination position is still disappearing, `after` (the default) shows the new one once it has disappeared. When a character already on screen moves there with `at=`, it leaves its old position right away and appears at the destination once the other has disappeared (with `slide=true`, it slides once the other has disappeared). `cross` shows the two overlapping, as in the earlier version |
| The name box while waiting for a character to appear | `wait=true` of `@chara`, `ui.chara.keepText` | While waiting for a character who isn't on screen yet to appear, the name box and text are cleared if the speaker of the previous page isn't that character. With `keepText` set to `true`, they aren't cleared. Since 0.4.1, though, the name and text are also cleared at the first command after a page turn (`ui.message.keepText` in [player.md](../player.md)), so to keep them as in earlier versions, set `ui.message.keepText` to `true` too |

- Speaker focus works automatically by tying the speaker in the name box to a character (the character whose ID or `speaker` in cast.json matches the speaker).
  During narration, and when the speaker's sprite isn't on screen, no one is changed. Even if the display name is changed (`{name …}`, `@name`), the speaker is what counts.
- Items written with `@chara-config` take priority over the game settings (`@chara-config focus=none` turns it off from that point). They're kept in the state, so loading gives the same.
- To make replacing behave as in the earlier version for the whole game, write `"swap": "cross"` under `chara` in `commandDefaults`.
- The name box and text aren't cleared while waiting for a character to appear after narration or after that character's own dialogue. They aren't cleared on the NVL or chat screens either.
- The syntax check warns about showing a character again right after hiding them (`chara-reshow`) and about hiding everyone for every line of dialogue (`chara-hide-per-line`) (chapter 9).
  Where one character is shown on the line right after hiding everyone, it adds a suggested fix (info, `chara-solo`) that makes them one line with `solo=true`, and `lim check --fix chara-solo` fixes them all across the project at once.

### How the sprite set and variant are decided

- Sprite set: the first one that exists, in this order: the one written → the character's `defaultAppearance` → `default` → the first one.
- Base variant (the variant used when only a sprite set is written): the sprite set's `defaultVariant` → `normal` → `default` → the first one.

If none of these exist, the choice falls to the order they're listed in, so the syntax check warns (`cast-ambiguous`). It applies to:

- Sprite sets without `defaultVariant` that have neither `normal` nor `default`
- Characters whose default sprite set can't be decided
- Variants whose `frame` has no `left` `center` `right`

### Position

| How to write it | Placement |
|---|---|
| `at=name` | A position in `positions` of the variant's `frame`. A variant with a `frame` always has `left` `center` `right`. At run time, an unknown name is shown at `center` (like tatie), but the syntax check treats it as an error |
| `at=auto` | Automatic placement. `auto` sprites are lined up side by side (see below) |
| `x=` `y=` | Top-left coordinates (px). An axis you write takes priority over `at` (`at=auto y=40` places it automatically only horizontally). When you write both `x` and `y`, don't write `at` (it's an error) |

Automatic placement (the same as TyranoScript's `pos_mode`):

- The later a sprite is shown, the further left it's placed.
- Their centers are placed at points that divide the screen width into (count + 1) equal parts, and their bottom edges are aligned with the bottom of the screen.
- Each time a sprite is shown or hidden, the remaining `auto` sprites slide to line up again.

### Layered sprites

For layered sprites (`layers` in chapter 10), you can add layer pictures to a variant by joining them with `+`.

```
@chara Yuika smile+blush
@chara Yuika +closed
```

- The first adds the cheek layer's `blush` on top of the variant `smile`. If you omit the variant as in the second, it's added to the base variant.
- What follows `+` can be the name of a picture in any layer. If you write two pictures from the same layer, the later one wins.
- An unknown name is a syntax check error, just like an unknown variant.

### Color tone, depth, depth of field

**Color tone**

- `@tone night time=1s`: changes the color tone of all sprites (including ones shown later).
- `@tone sepia who=Yuika`: changes only that character.
- `@tone none`: resets it (if the background has a color tone, back to the background's tone).
- The built-in tones are `sepia` `mono` `night` `evening` `dark`, and `plain`, which doesn't change the color. You can add or replace them with `ui.tones` in liminalia.json.
- Backgrounds can have a color tone too. Set it with `@bg room_night.jpg tone=night` or with `ui.backgroundTones` in liminalia.json (background file name → tone name), and while that background is shown, its tone is applied to the sprites (even without writing `@tone`, sprites don't stand out against a dark room or an evening background). When `@bg` changes the background, the sprites' tone changes with the same `time` as the background, and changing to a background without a tone removes it. `tone=` of `@scene-change` works the same way.
- The tone applied to a sprite is decided in this order: the per-character one from `@tone`, the one for all sprites from `@tone`, then the background's tone. For a character who shouldn't get the background's tone, write `@tone plain who=…`. `tone=none` in `@bg` doesn't apply a tone at that point, even for a background listed in `ui.backgroundTones`.

**Backgrounds with depth (`@plane`)**

- `@plane name image depth=0.9` layers a bgimage picture over the background.
- When you move `@camera`, it moves less according to its depth (0 to 1). 0 moves with the sprites, and values closer to 1 move less. Negative values are in front and move more.
- `front=true` places it in front of the sprites. Farther planes are layered further back.
- While the camera is moving, it also moves with the same time and easing as the camera. At every point along the way, it moves less according to its depth.
- `@plane-hide` or `@bg` removes it.

**Depth of field (`@dof`)**

| How to write it | In focus | Blurred |
|---|---|---|
| `@dof sprites` | Sprites | Background and foreground images |
| `@dof background` | Background | Sprites and foreground images |
| `@dof who=Yuika` | That character | Background and foreground images. Other sprites at half strength |
| `@dof none` | | Resets it |

You can write `blur=` (px; default 6) and `time=`. It doesn't replace a filter from `@filter`; both apply.

### Face window

The expression in the face window (`ui.face` in liminalia.json) is decided in this order.

1. If that character's sprite is on screen, the sprite's variant
2. If not, the one set with `@face Yuika smile` (you can also write `appearance=`)
3. When the sprite is hidden, the variant from before it was hidden carries over
4. If there is none of these, the base variant

### State and loading

- Only the variant, sprite set, `at`, `x` / `y`, flip and stacking order (`z`) are kept in the state. The actual coordinates and size are calculated each time by the drawing side, from the state of the sprites on screen
  and the character definitions. Loading gives the same screen.

### What the syntax check can and can't find

- If a character, sprite set, variant or position isn't in cast.json, it's an error with candidates of similar spelling
  (`unknown-cast` `unknown-appearance` `unknown-variant` `unknown-position`).
- Combinations that come from keeping values you didn't write (changing only the outfit when that outfit doesn't have the current expression, and so on) can't be found by the syntax check.
  They're checked on every `@chara` at run time and become runtime diagnostics (you can find them with `lim coverage` and on Studio's Check screen).

## 7. Voice

```
@voice yui/001.ogg
Yui "Good morning."
@voice-auto Yui pattern="yui/{n:3}.ogg"
Yui "This line plays yui/001.ogg."
Yui "This line plays yui/002.ogg."
Ren "Wait{@voice ren/wait.ogg}"
```

- Put voice files in `assets/voice/` (`folder=sound` also looks in the sound effects folder).
- `//!` lines directly above a line of dialogue are acting notes (`//! Whispering`). They go in the "acting notes" column of the recording script (`lim voice-script`). Plain `//` comments aren't included
  (to include every `//` line as before, write `"voiceScript": { "notes": "comments" }` in liminalia.json).

**Playing one at a time (`@voice`)**

- Written before a text line, it plays once with the next line of dialogue.
- Written inside text, it plays on the spot and becomes the voice of that page.

**Playing numbered files (`@voice-auto`)**

- `@voice-auto speaker pattern=…` plays a numbered file for each of that speaker's lines. `{n}` is the number, and `{n:3}` pads it to 3 digits.
- A line with `@voice` plays that file instead, and the number doesn't advance.
- `@voice-auto-off` stops it while keeping the number. `@voice-auto speaker` (without `pattern`; omit the speaker too for all) resumes it.
- `start=false` only sets up the numbering and leaves it stopped without starting to play (`[voconfig]` in TyranoScript). To start it, write it the same way as resuming above.
- The number is kept in the state, so after loading, the same line plays the same file.

**Locking the numbers (`lim voice-lock`)**

With numbered voices, adding one line of dialogue shifts every number after it, and the numbers also change depending on which branch was taken.
Once the voices are recorded, lock a number to each line with `lim voice-lock` (`voice-lock.json`; chapter 10).
With a lock, the locked number plays, and lines that aren't in the lock (lines added after recording) don't play.
Numbers are given only to lines where `@voice-auto` is in effect and there is no `@voice`, as at run time (lines before it's set, after `@voice-auto-off`, and lines with `@voice` don't get numbers).

**Playback**

- Moving to the next page stops the previous voice (you can also choose "Keep playing" for "On advance" in the Settings screen).
- In auto mode, the page advances after the voice finishes. While skipping, voices don't play.
- You can replay the voice of each page from the backlog.

**Two people speaking at once (`who=`, `channel=`)**

```
@voice yui/010.ogg
@voice mika/010.ogg who=Mika
Yui "Ready, set..."
```

- Writing two `@voice` lines with different speakers (`who=` gives the speaker of that voice) before the same line of dialogue plays both at once. Putting them on different channels, as in `channel=2`, also plays them at once
  (a second one with the same speaker and the same channel replaces the first).
- Lip sync moves the mouth of each voice's speaker while that voice plays, and the name box shows both names ("Yui, Mika"). The backlog, text-to-speech, and copying the text use the same names. The setting that highlights the speaker (`@chara-config focus=`) applies to both too.
- Both speakers appear in the per-speaker voice volume in the settings (they count as speakers whose voice was heard).
- Auto advances after the longest voice finishes. Replaying from the log plays both.
- The recording script (`lim voice-script`) and the voice screen in Studio also list the second voice as a line (its speaker is the `who=` speaker).

**Sound filters (`filter=`, `@voice-filter`)**

```
@voice-filter phone who=Mika
Mika "Hello? Can you hear me?"
@voice-filter none who=Mika
@bgm night.ogg filter=muffled filter-strength=60
@bgm night.ogg filter-fade=1s
```

- `filter=` is `muffled` (a muffled sound: through a wall, underwater), `phone` (over the phone), `radio` (a radio or walkie-talkie), `hall` (the echo of a large hall) or `none` (no filter).
  `filter-strength=` (0 to 100) mixes it with the original sound. It can be written in `@bgm`, `@se` and `@voice`.
- `@voice-filter kind who=speaker` keeps applying it to that speaker's voices (omit `who` for all speakers; `none` removes it). It applies right away to a voice that's playing too (over `time=`), and it's kept in the save.
  `@voice … filter=none` removes it for that voice only.
- Writing `@bgm` again for the same track that's playing changes only the filter, without stopping the track (over `filter-fade=`; without `filter`, it's removed).
  Filters on BGM and looping sound effects are kept in the save, and loading plays them with the same filter.

**Captions (`caption=`)**

Giving a caption to a voice that isn't written in the text (laughter, a sigh, words different from the text), as in `@voice yui/laugh.ogg caption="(laughs)"`,
shows it to players who have turned on "Sound captions" in Settings, in the same place as sound effect captions. In translation files, it can be translated as command text.

**Text only for reading aloud (`@describe`, `alt=`)**

```
@bg classroom_rain.webp alt="A classroom at dusk. Rain is falling outside the window"
@describe "Yui silently looks out the window"
Yui "..."
```

- `@describe "…"` isn't shown on screen. Before the next text (or choice), it's passed to screen readers (an aria-live region that isn't visible) and
  to text-to-speech (in Settings). Use it to describe scenes that are conveyed only by pictures or effects.
- `alt=` in `@bg`, `@chara` and `@image` passes a description of that picture in the same way (each time the picture is shown; pictures shown while skipping aren't passed).
- Both can be translated as command text (Languages).

## 8. Conditions, choices, variables

```
@if game.trust >= 2
Yui "Then this will be quick."
@elif game.trust == 1
Yui "...I'll think about it."
@else
Yui "...I see."
@end

@choice
- Take the north road -> #north_road
- Take the south road -> #south_road
@end

@set game.trust += 1
@let count = game.trust * 2
@jump chapter2#start
@call common#interlude
@return
```

### Blocks

- A block is always closed with `@end`. Indentation is only for looks.
- Put labels outside `@if`. A label inside `@if` is an error (`label-in-if`), because jumping into it would start in the middle of a branch without checking the condition. At run time too, a jump to that label is an error, and the jump isn't made.

### One-line conditions (`if=(expression)`)

```
@bg room_night.jpg if=(game.night)
@chara Yuika smile if=(game.trust >= 2) time=300ms
@set game.met = true if=(!game.met)
@jump #bad_end if=(game.trust < 0)
@return if=(temp.done)
```

- `if=(expression)` can be written on any command line, including `@jump` `@call` `@set` `@let` `@return` `@content`. If it's false, the line is skipped (`cond=` in TyranoScript, `if:` in Naninovel).
- It behaves the same as wrapping the line in `@if expression` to `@end`, and the syntax check and the flowchart see it the same way (the line after `@jump … if=(…)` is reachable, and the arrow on the map gets the condition).
- It can also be written in the middle of the arguments (`@bgm night.ogg if=(game.night) volume=60`). The value is always in `(…)` (`if=game.x` is `bad-guard`; the suggested fix is `if=(game.x)`).
- It can't be written on words that open blocks (`@if` `@elif` `@else` `@while` `@for` `@with` `@choice` `@define` `@function` `@script` `@use` `@end`) or in `{@…}` in text (`bad-guard`). To show choices conditionally, write `if=` on the choice line.
- The name of a `@let` with `if=(…)` can be used in later lines too (if the condition is false, it stays without a value).
- `lim backport` writes it back as `cond="…"` (commands that become two or more tags are wrapped in `[if exp="…"]` to `[endif]`).

### Jump targets

| How to write it | Where it goes |
|---|---|
| `#label` | A label in the same file |
| `file` | The start of that file |
| `file#label` | A label in that file |
| `(expression)` | Decided at run time (`@jump (game.next)`). The value is a string in one of the three forms above |

A file is a path relative to the scenario folder, without the `.lim` extension. Scenarios in subfolders are separated with `/`
(for `scenario/part1/chapter2.lim`, `@jump part1/chapter2#top`). `lim check`, `lim build` and Studio treat scenarios in subfolders by the same names
(files and folders starting with `.` are ignored).

When the target is decided by an expression, the syntax check and the flowchart still read the candidate targets from the expression and confirm that each one exists.

- Strings in the expression (`(game.good ? "#a" : "#b")`)
- If the expression is only a variable, the strings that `@set` puts in that variable and its initial value in liminalia.json
- For a local variable from `@let`, the expression of that `@let`

When they can't be read (there is a `@set` that puts in something other than a string, the variable receives a command's result, and so on), write the candidates with `to=`.

```
@jump (game.next) to=#north,#south
- Text -> (game.next) to=#a,#b
```

- If the candidates can't be read and there is no `to=`, it's a warning (`unknown-targets`).
- With `to=`, a jump at run time to a target that isn't among the candidates is an error instead of a jump.

### Choices

```
@choice
- Check the door -> #door image=button/door.png hover=button/door_on.png x=120 y=300
- -> #window x=600 y=200 width=180 height=240
@end

@choice timeout=10s default=2
- Use the key -> #unlock if=(game.has_key)
- Turn back -> #back
@end
```

A choice line is `- text -> target`, and you can write its look and conditions after the target.

**Look**

| What you write | Look |
|---|---|
| `image=` (`hover=` too) | Image button |
| No `image=`, but `width=` and `height=` | Invisible click area |
| Neither | Text button |

- `x=` `y=` set where it's placed.
- The text is used in records without a screen and for text-to-speech. It can be omitted only for image buttons and click areas (`- -> #window …`).

**Conditions and state**

| How to write it | Meaning |
|---|---|
| `if=(expression)` | Shown only when true. False choices aren't shown, and the rest close up (same as `[glink cond=…]` in TyranoScript). The expression is always in `(…)`, and true and false are judged the same way as `@if` |
| `locked=(expression)` | If true, shown but can't be pressed, instead of being hidden. Can be written together with `if=` |
| `call=true` | Calls the target (`@call`), and after `@return` comes back to this choice and shows it again (for buttons that switch settings and so on) |

- You can't wrap choices in `@if` to show them conditionally (only choice lines can go inside `@choice`).
- If every `if=` is false, no choices are shown, and the game stops in a state where clicking doesn't advance (same as `@stop`).
  It's the same as `[s]` after `[glink]` tags whose conditions are all false in TyranoScript, and a runtime warning `no-choice-shown` is given.
- If every choice has `if=`, none might be shown and the game might stop, so the syntax check warns (`all-options-conditional`).
  However, under the following conditions it tries every combination of variable values, and doesn't warn if one choice is sure to be true
  (such as a last choice that's shown only after all the others have been done).
  - The conditions only use variables as booleans as they are, or compare them with values using `==` `!=`, joined with `!` `&&` `||`
  - A variable compared only with `true` `false` is either true or false; other variables are taken to be one of the compared values, unset, or something else

**Time limit**

- Write `@choice timeout=10s default=2` on the `@choice` line. A bar shows the remaining time, and when time runs out, the `default` choice (counting from the top) is chosen.
- While screens such as the menu, save, load, backlog or settings are open, the remaining time doesn't go down (the bar stops too). When they close, it continues from where it was.
- If `default` is omitted, or that choice isn't shown or can't be pressed, nothing is chosen and the game moves on past `@end`.

### Expressions

A small expression language, not JavaScript.

- What you can use: arithmetic, comparison, logic, the ternary operator, arrays `[1, 2]`, dictionaries `{"a": 1, b: 2}`, indexing, registered functions (random numbers, numbers, strings and arrays, the real date and time; the list is under "Expression functions" in [commands.md](../commands.md)), and functions made with `@function` (below)
- Functions that change arrays (`push` and so on) return a new array without changing the original.
- Strings are only `"…"`. Assignment is done only with `@set` and `@let` (both take `=` `+=` `-=` `*=` `/=`; `@let i += 1` is the same as `@let i = i + 1`).
- Dictionary keys are `"strings"` or names. Writing the same key twice is a syntax check error. Read them with `game.d.a` or `game.d["a"]`. They can be written inside `{= …}` too, as in `{= {"a": 1}["a"]}` in text.

| Operation | Rule |
|---|---|
| `==` | Compares types too |
| `+` | Adds if both are numbers. If either is a string, joins them (`"Chapter " + game.n`; numbers and booleans become text). Any other combination is an error |
| `/` | Dividing by 0 is an error (it doesn't silently become `null`) |
| Function call | A wrong number of arguments is a syntax check error (`bad-arguments`) |

Progress and the environment being played in (functions answered by the runtime):

| Function | Value |
|---|---|
| `visits("#label")` | How many times that label has been entered in this playthrough (kept in the save). It's counted when the label line is passed, so read inside that label, it includes the current visit. It's 1 on the first visit |
| `read("#label")` | Whether that label has ever been entered in any playthrough (read status; shared by all saves) |
| `chosen("choice text")` | Whether the choice with that text has been chosen in this playthrough (kept in the save) |
| `lang()` | The language being played (`ja`, `en` and so on) |
| `platform()` | `pc` or `mobile` (phones, tablets) |
| `app()` | Whether it's being played in an app (desktop or mobile version). `false` in a browser |
| `replaying()` | Whether a replay from the extras is playing |

```
# check_arms
@if visits("#check_arms") == 1
  Both arms are gone, cut off halfway down the upper arm.
@else
  No arms.
@end
@jump #menu
```

- Targets in `visits` and `read` are written the same way as for `@jump` (`#label`, `file`, `file#label`). A file alone gives how many times the start of the file was entered.
  Entering a label counts whether it's reached by a jump (`@jump` `@call`, choices) or by continuing from the line above.
- The syntax check confirms that labels and files in targets written as strings exist (`unknown-label` `unknown-file`), and that the choice in `chosen` exists somewhere (warning `unknown-option`).
  The text in `chosen` is the choice text with ruby replaced by its base text (the original, not a translation).
- When running without a screen (`lim trace`, the all-routes test), `lang()` is the language of the original, `platform()` is `pc`, and `app()` and `replaying()` are `false`.
- TyranoScript's expressions don't have these, so `lim backport` reports expressions containing them as things it can't write back.

Random numbers:

- `random()` is 0 or more and less than 1, and `random(n)` is an integer from 0 up to but not including n.
- Random numbers are made from a seed (`seed`), and the seed advances each time a random number is made. The seed is kept in the save, so loading gives the same results.
- `lim coverage` runs with one fixed seed by default (`--seeds N` runs N times with different seeds).

### Variables

| How to write it | Lifetime |
|---|---|
| `game.x` | Kept in the save |
| `system.x` | Shared by all saves |
| `temp.x` | Only during the current session |
| `@let x = …` | Local variable. Only within that file or `@define` |
| `save.version` | Read only. The version of the game that made the save data ("Save versions" below) |

- Initial values go in `variables` in liminalia.json (`{ "game.trust": 0, "system.cleared": false }`).
  - `game.` starts with this value every time the player chooses "New Game." Variables missing from a loaded save are also filled in with this value.
  - `system.` gets this value when it doesn't have a value yet.
  - `temp.` can't be written here.
- `__proto__`, `constructor` and `prototype` can't be used in variable names, members or keys (`game.x`, `game["x"]`, `@let` names, `@define` parameter names)
  (syntax check error `forbidden-property`). At run time too, an assignment that goes through them is an error and isn't made, and reading them gives `null`.
- **Misspellings are reported.** When a `game.` or `system.` variable is read but never given a value anywhere (not by `@set`, a command's result, an initial value in `variables`,
  a plugin's declaration, a flag in the project's data, a record of unlocks the engine sets, or anything else), and a variable that is given a value has a similar spelling, it's a warning
  (`unset-variable`; the suggested fix replaces it with that name: `@if game.socre` → `game.score`). If there's nothing similar, it isn't reported (so that variables a plugin sets silently aren't reported by mistake.
  Variables a plugin sets go in the plugin's `variables`; see docs/plugins.md).
- Setting `check.variables` in liminalia.json to `"declared"` allows only the variables written in `variables`. Every place that reads or writes a `game.` or `system.` variable that isn't written there gets a warning (`undeclared-variable`).
- **Variables with no initial value.** A variable with no value yet is `null`. `+=` `-=` `*=` `/=` calculate `null` as 0 (an empty string when adding text with `+=`),
  but comparisons (`<` `<=` `>` `>=`) and arithmetic (`+` `-` and so on) don't treat it as 0 (`null >= 2` is a runtime error). A place that reads a variable with no initial value in `variables`
  that is never given a value with `=` and only calculated with `+=` and the like gets a warning (`uninitialized-variable`; on a route that didn't pick the option that adds to it, it's compared with no value).
  To fix it, write an initial value in `variables` (`"game.trust": 0`). `temp.` can't go in `variables`, so give it a value first with `@set temp.x = 0`.
  For a `@let` local variable, `@let x += 1` is the same as `@let x = x + 1` and doesn't treat `null` as 0. A line that calculates a local variable from its previous value
  without a `@let x = …` on an earlier line (and that isn't a parameter or the `@for` name) also gets a warning (`uninitialized-variable`; the fix is `@let x = 0` on the line before).
- When the expression of a condition (`@if` `@elif` `@while` `@for`, a line's `if=(expression)`, a choice's `if=` `locked=` `call=`, `if` in the data of standard commands) gives an error,
  a runtime error (`runtime`) is reported and the condition is treated as false (the branch for a true condition isn't entered).

```json
"check": { "variables": "declared" }
```

### Macros (`@define`)

```
// Scene change macro (the one in the earlier template; the current template uses @scene-change and commandDefaults)
@define scene(image: asset(bgimage), time: duration = 800ms)
@window hide
@chara-hide-all time=(time)
@mask time=(time)
@bg (image)
@mask-off time=(time)
@window show time=300ms
@end

@scene image=room_night.jpg
```

- `@define name(parameter: type = default, …)` to `@end`. The types are `string` `number` `int` `bool` `duration` `color` `variable` (a variable that receives the return value; see below).
- You can also write types that are checked the same way as for built-in commands. The syntax check looks at the caller's values just as it looks at a command's arguments.

  | Type | Value | What it checks |
  |---|---|---|
  | `asset(folder)` | An asset path (for `asset(bgimage)`, from the background folder) | That the asset exists (`missing-asset`, `asset-case-mismatch`) |
  | `cast` | A character | That it's in cast.json |
  | `appearance` `variant` `position` | A sprite set, variant, position | That the character given as the same macro's `cast` value has it |
  | `target` | A jump target (`#label`, `file`, `file#label`) | That the label and file exist |
  | `enum(a\|b\|c)` | One of fixed values | That it's one of the values written |

- `//` lines directly above `@define` are shown in completion and descriptions as a summary of the macro.
- A call has the same form as a command (`@scene image=room_night.jpg`). Inside, pass parameters to commands as `(parameter name)`.
- An expression inside a macro that jumps to a parameter's value, such as `@jump (to)`, is checked by the syntax check with the caller's values (make the type `target`).
- A macro with the same name as a built-in command is used instead of the command (warning `define-shadows-command`; the game doesn't break when a newer version of the engine adds a command with the same name). Syntax words such as `@if` and `@jump` can't be macro names (error).
- A `-` in a parameter name is written `_` in expressions inside (`first-name` is `{= first_name}`, because `-` in an expression is subtraction).
- Macros don't change the caller's variables. A `@let` inside with the same name as a parameter is an error (`shadows-param`).

**Loops (`@while`)**

```
@let i = 0
@while i < 3
  Round {= i + 1}
  @let i = i + 1
@end
```

- Repeats up to `@end` while the condition is true. The condition is judged the same way as `@if`. `@elif` `@else` can't be written. Labels can't be placed inside (`label-in-if`).
- The runtime stops when the number of lines it has run goes over a limit (default 1,000,000), so a loop that never ends stops there too. Text lines and each check of the loop condition count as one line each, not only command lines. The count isn't reset for each loop; it's the total of every line the runtime has run.

**Looping over arrays (`@for`)**

```
@for item in game.items
  You have {= item}.
@end
@for name in keys(game.flags)
  @set game.flags[name] = false
@end
```

- `@for name in expression` to `@end`. If the expression's value is an array, its elements, and if it's a dictionary, its keys, are put into the name one at a time, and the inside repeats (anything else is a runtime error; a literal number or string is the syntax check's `bad-for`).
- The expression is evaluated only once, before starting (rewriting `game.items` inside doesn't change what's looped over). The name is a local variable (as with `@let`, it can also be read after `@end` and keeps the last value; if the loop never runs, it has no value).
- `@elif` `@else` can't be written. Labels can't be placed inside (`label-in-if`). Loops can be nested. `game` `system` `temp` `save` can't be used as the name (`bad-for`).
- TyranoScript has no equivalent, so `lim backport` reports it as something it can't write back, as with `@while`.

**Expression functions (`@function`)**

```
@function rank(score) = score >= 80 ? "A" : score >= 50 ? "B" : "C"
@function heart(n) = n >= 3 ? "♥♥♥" : n == 2 ? "♥♥" : "♥"

Yui "Your grade is {= rank(game.score)}."
@if rank(game.score) == "A"
  …
@end
```

- `@function name(argument, …) = expression` on one line makes a function that can be called in expressions. Its body is a single expression, and it only returns a value (it doesn't change variables). Write it at the outermost level of the file (`nested-function`).
  It can't be written in a block form from `@function name(arguments)` to `@end` (reported once as `bad-function`; if the body is a single `@return`, the suggested fix is the one-line form).
- Inside, it can read its arguments and `game` `system` `temp` `save`. The `@let` local variables of the place that calls it aren't visible (so it behaves the same whenever it's called).
- It can be called in that file and in files that `@use` that file (as with macros). If you forget `@use`, the syntax check shows which file to `@use`.
- A function can't have the same name as a built-in function (`random` and so on) (`duplicate-function`). A wrong number of arguments is `bad-arguments`.
- A function can call itself. If calls go deeper than 200 levels, it stops with a runtime error.
- The return value of a macro (`@define`) (`@return (expression)`) can't be used inside expressions. Macros show text and effects and may wait for them to finish, so they can't run in the middle of an `@if` condition or `{= …}` in text. Use `@function` to only calculate a value, and a macro for effects.

**Passing content (`@with` and `@content`)**

```
@define flashback(time: duration = 1s)
@tone sepia time=(time)
@content
@tone none time=(time)
@end

@with flashback time=600ms
Yui "...About that day."
@end
```

- `@with macro parameters…` to `@end` passes the lines in between to the macro as content. The content runs where `@content` is in the macro (it can be written any number of times).
- The content runs with the caller's local variables (`@let`). Labels, `@content` and `@return` can't be written in the content.
- Calling a macro without `@content` with `@with` is a warning (`with-without-content`; the content doesn't run). Calling a macro with `@content` without `@with` makes `@content` do nothing.
- Only `@define` macros can be called with `@with` (writing a command gives `bad-with`).

**Return values (`@return (expression)`)**

```
@define roll(sides: int = 6, into: variable)
@return (randint(1, sides))
@end

@roll sides=20 into=temp.r
```

- Give the macro one parameter of type `variable`, and `@return (expression)` puts a value in that variable and ends the macro. The caller passes the variable to fill (`game.x` `system.x` `temp.x`).
- `@return (expression)` can only be written inside `@define` (`bad-return`). `@return` without a value works as before.
- TyranoScript has no return values, so `lim backport` reports macros that use a return value as things it can't write back, as with `@while` and `@with` (as with adding a `@define`).

**Using macros from another file (`@use`)**

- Write `@use file` at the outermost level of the file (`@use common`). Only the `@define` macros of the files you `@use` can be called.
- At run time, that file is loaded first (they can still be called after loading a save). Only the `@define` macros are loaded; the file's text doesn't run.
- Even if files `@use` each other (even in a loop), each is loaded only once.
- If you call one without `@use`, the syntax check shows which file to `@use`.

## 9. Syntax check

It checks the scenarios and project files before running. Mistakes are reported with the line and a suggested fix.

### Where it runs

| Place | What it does |
|---|---|
| `lim check` | Checks every scenario in the project. `--json` gives machine-readable output |
| The VS Code extension, the Studio editor | Run the same check while you write and underline mistakes with a wavy line |
| `lim build` | Checks before exporting |

`lim check` fails (exit code 1) if there is even one error. With only warnings, it succeeds.

### Reading the output

The messages are in Japanese by default; with `--lang en` they're in English. For example, `lim check --lang en` prints:

```
start:12 error [unknown-label] The label #nort_road isn't in this file
    → Did you mean #north_road?

1 files, 1 errors, 0 warnings
  unknown-label: 1
```

Each diagnostic has the following. With `--json`, each element of `diagnostics` has this form.

| Item | Contents |
|---|---|
| `file` `line` `column` | Location. Lines and columns count from 1. The column is omitted for problems with a whole line |
| `severity` | `error`, `warning`, `info` |
| `code` | A machine-readable identifier (`unknown-label` and so on). `lim explain code` shows a description, examples and how to fix it |
| `message` | What is happening |
| `hint` | Suggested fix. Written, where possible, as the line itself fixed rather than as a fixed template. Sometimes there is none |
| `fix` | A line fix a machine can apply (`replace` replaces `find` with `with`, and `delete-line` deletes the line). Sometimes there is none |
| `fixes` | Candidate fixes, in order of recommendation. Besides line fixes, it includes ones that rewrite things outside the line (`add-speaker`: adds `name` to `speakers` in cast.json; `add-label`: adds a `# label` line at the end of `file` to create the scene) |

Diagnostics are sorted by file, line and column (`--json` too).

Command names, parameter names, labels, files, characters and speakers with a similar spelling appear in the suggested fix as "Did you mean …?"
For labels and files, only names that differ little relative to their length are suggested (`#start` isn't suggested for `#stay`).
For a jump target that doesn't exist, "Create the scene" (`add-label`) comes before replacements. For a value of the wrong type, the suggested fix is the line with only the value fixed
(removing `who=` attached to an unnamed parameter, and for a duration without a unit, `1s` for a small number and `300ms` for a large one).

### What it checks

The main checks, by category.

**Syntax**

| code | Severity | Contents |
|---|---|---|
| `bad-encoding` | Error | A script can't be read as UTF-8 (saved in Shift_JIS and so on; it isn't read garbled. Save it again as UTF-8). `lim check` gives no other diagnostics for that file, and `lim trace` and `lim coverage` stop at that file |
| `bad-label` | Error | A malformed label: written without a space as in `#name` (correctly `# name`), or a name with characters other than letters, digits, `_` and `-` |
| `bad-command-name` | Error | A command name with characters other than lowercase letters, digits and `-` (`@Bg`, `{@ bg}` and so on) |
| `bad-define` `bad-param` | Error | A malformed `@define` (not `@define name(parameter: type = default, …)`), a malformed parameter |
| `nested-define` `nested-use` | Error | `@define` and `@use` not at the outermost level of the file |
| `bad-set` `bad-set-target` `bad-let` | Error | Not in the form `@set variable = expression`, the left side of `@set` isn't a variable, not in the form `@let name = expression` (both can use `=` `+=` `-=` `*=` `/=`) |
| `bad-guard` | Error | `if=` on lines with words that open blocks (`@if` `@while` `@for` `@with` `@choice` `@define` and so on) and in `{@…}` in text, and `if=` not written in `(…)` (`if=game.x` is fixed to `if=(game.x)`; chapter 8) |
| `bad-for` | Error | Not in the form `@for name in expression`, the first part of a variable name such as `game` used as the `@for` name, or looping over a value that is neither an array nor a dictionary, such as a literal number or string (chapter 8) |
| `bad-function` `nested-function` `duplicate-function` | Error | Not in the form `@function name(argument, …) = expression` (the block form up to `@end` is reported once, and if its body is a single `@return`, the one-line form is the suggested fix), not at the outermost level of the file, the same name as a built-in function or another `@function` (chapter 8) |
| `bad-use` | Error | Not in the form `@use file` |
| `bad-option` `empty-option` | Error | A line inside `@choice` that isn't `- text -> target`, a choice without text (except one with `image=`, which makes an image button, or with `width=` and `height=`, which make a click area) |
| `bad-target` | Error | A jump target that's none of `#label`, `file` and `file#label`, or something other than `to=` after a jump target written as an expression |
| `missing-expression` | Error | An empty expression in `@if` and so on |
| `unclosed-string` `unclosed-paren` `missing-value` `unexpected-argument` | Error | An unclosed `"…"` or `(…)` in a parameter, no value after `name=`, a parameter written on a command that takes none |
| `bad-color` `bad-size` `bad-speed` `bad-image` `bad-fx` | Error | A mistake in `{c #color …}` `{mark #color …}`, `{size 32 …}`, `{speed 600ms …}`, `{img path}` or `{fx wave …}` in text (chapter 3) |
| `duplicate-label` | Error | The same label twice in the same file |
| `unclosed-block` `orphan-end` `orphan-branch` `branch-after-else` | Error | An unclosed block such as `@if` `@while` `@with` `@choice` `@define`, or an `@end` `@elif` `@else` without a matching block |
| `bad-with` `bad-content` `bad-return` | Error | A malformed `@with`, `@content` outside `@define`, or a `@return (expression)` that can't return a value (chapter 8) |
| `with-without-content` | Warning | A macro without `@content` called with `@with` (chapter 8) |
| `label-in-if` | Error | A label inside `@if` (chapter 8) |
| `stray-brace` `unclosed-inline` `unknown-inline` `dangling-escape` | Error | Unmatched `{…}` in text, unknown syntax, `\` at the end of a line |
| `noclick-not-last` `noclick-in-option` | Error | `{noclick}` that isn't at the end of a line, `{noclick}` in choice text (chapter 3) |
| `bad-speaker-name` | Error | A mistake in a display name `{name …}` (empty, something other than characters and `{= expression}`, no dialogue bracket or quotation mark right after it; chapter 2) |
| `empty-ruby` `bad-ruby` | Error | Empty base text or reading in ruby, or no `\|` separating the reading, or a full-width `｜` (chapter 3) |
| `aozora-ruby` `tyrano-tag` | Warning | 《》 ruby and TyranoScript tags (`[p]` `[l]` `[r]` `[cm]` `[er]`) left in the text. They're shown as is |
| `unknown-speaker` | Warning | A line shaped like dialogue that became narration (including `ユイ：「…」` `【ユイ】「…」`, `{name …}` on a name that isn't a speaker, and `Nora: "…"` on two or more lines of the same file; chapter 2) |
| `fullwidth-symbol` `option-outside-choice` | Warning | A full-width `＠` `＃` `／／` at the start of a line, a full-width `＝`, a choice line outside `@choice` (chapter 2) |
| `trailing-comment` | Error, warning | `//` at the end of a line (an error on command and choice lines, a warning on dialogue and narration; chapter 2) |
| `duplicate-line-id` `bad-line-id` | Error, warning | A fixed line ID used twice in the same file, a `#line:` with characters other than letters, digits, `_` and `-` (chapter 2; a `#line:` that isn't a line ID is shown as text) |
| `invisible-space` | Warning | Invisible characters (see below) |

**Commands and parameters**

| code | Severity | Contents |
|---|---|---|
| `unknown-command` | Error | An unknown command. If it's a macro in another file, `@use` appears in the suggested fix |
| `renamed-command` | Error | A command with a name from an earlier version (`@scene` is now `@scene-change`). The suggested fix replaces it with the current name, and `lim migrate` fixes the whole project ("Script format versions" in chapter 10). Not reported if there's a macro with the same name |
| `renamed-param` | Warning | A parameter with a name from an earlier version (`@bg x.jpg fade=1s` is now `time=1s`). It keeps working under the old name. The suggested fix replaces it with the current name, and `lim migrate` fixes the whole project ("Script format versions" in chapter 10). Parameters of a macro with the same name aren't reported |
| `legacy-ending` | Warning | In a project with script format 2 or earlier, wording written in `ending=` of a command that ends the playthrough (`ending="BAD END"`), the earlier way. The suggested fix splits it into the kind and `title=`, and `lim migrate` moves the whole project ("The end of a playthrough" in chapter 2) |
| `unknown-ending-kind` | Error | An ending kind that doesn't exist (from script format 3; the suggested fix is the closest kind name, or for wording, the kind and `title=`). A kind in `playtest.avoidEndings` or `endings()` in an expression that matches nothing is a warning |
| `unknown-param` `missing-param` `too-many-positional` | Error | An unknown parameter, a missing required parameter, too many unnamed parameters |
| `ambiguous-bool-shorthand` | Error | A boolean written as just its name could also be read as the value of an unnamed parameter. Write the boolean as `name=true` |
| `positional-by-name` | Error | An unnamed parameter written with a name |
| `duplicate-param` | Error | The same parameter written twice |
| `bad-effect-mask` | Error | The `mask=` of `@filter` or `@effect` can't be read (`"radial x y width height"` or `"radial-out x y width height soft"`, all in px) |
| `flipbook-frames` `flipbook-data` | Error | A mistake in how the frames of `@flipbook` are written (neither `image` nor `data`, `{n}` in `image` but no `frames`, and so on), the JSON of `data=` doesn't exist |
| `flipbook-missing` | Warning | Frame images of `@flipbook` aren't in the asset folder |
| `flipbook-loop-wait` `flipbook-off-unknown` | Warning | `wait=true` written on `loop=0` (repeat until stopped; it moves on without waiting), no `@flipbook loop=0` has the name of `@flipbook-off` in its `name=` |
| `effect-mask-ignored` | Warning | `mask=` on a `@effect` type that can't be limited to an area (`wave`, `glitch`, `chromatic`; it covers the whole screen. Choose where it applies with `layer=`) |
| `flash-rate` | Warning | A `@flash` that flashes more than 3 times a second (counted from `count`, `time`, `gap` and the project defaults; flashing light can cause seizures) |
| `hide-name-unknown` | Warning | No `@cutin stay=true`, `@hud-text` or `@hud-button` shows the name given to `@cutin-hide`, `@hud-text-off` or `@hud-button-off` (nothing is hidden). Not checked for a kind whose names are given as expressions |
| `bad-value` | Error | A value of the wrong type (a duration without a unit and so on). The suggested fix is the line with only the value fixed |
| `redundant-param` | Error | A parameter that isn't used when written together with another (`at` when both `x` and `y` are written, and so on) |
| `same-as-default` | Info | A parameter with the same value as the project default (`commandDefaults` in liminalia.json; `500ms` and `0.5s` are the same). With a fix that removes it. Values equal to a command's built-in default aren't reported |
| `scene-change-candidate` | Info | A block from `@mask` to `@mask-off` that does the same as one `@scene-change` (see "Merging into a scene change" below). With a fix that turns the block into one line |
| `scene-change-sprite-overlap` | Warning | The previous sprites haven't finished disappearing when the fade-in starts, so they may be seen faintly. The suggested fix is a `@scene-change` that finishes hiding them while the screen is covered and then fades in (fixing it changes how they disappear) |
| `chara-replace-conflict` | Error | `replace` on `@chara` conflicts with a position or with hiding everyone |
| `chara-replace-unknown` | Error | The character written in `replace` isn't in cast.json |
| `chara-replace-target` | Error | The character to replace isn't on screen, there's more than one character at that position, or the character to show is already on screen |
| `bad-expression` `unknown-variable` `unknown-function` `bad-arguments` | Error | A mistake in an expression, an undefined variable, an unknown function (if it's a `@function` in another file, `@use` appears in the suggested fix), the wrong number of function arguments |
| `unset-variable` `undeclared-variable` | Warning | A variable that's read but never given a value anywhere, when a variable that is given a value has a similar spelling (it's taken as a misspelling, and that name is the suggested fix), a variable not written in `variables` when `check.variables` is `"declared"` (chapter 8) |
| `uninitialized-variable` | Warning | Reads a variable with no initial value that is only calculated from its previous value with `+=` and the like (reaching that line before it's added to reads it with no value; chapter 8). The fix is an initial value in `variables` (for `temp.`, set a value with `=` first). Also a line that calculates a local variable from its previous value with `@let x += 1` and the like before any value is set (the fix is `@let x = 0` on the line before) |
| `forbidden-property` | Error | `__proto__` or similar used in a variable name and so on |
| `shadows-param` `duplicate-define` | Error | A `@let` with the same name as a macro parameter, two macros with the same name |
| `define-shadows-command` | Warning, error | A macro with the same name as a built-in command (the project's macro is used; warning), a macro with the same name as a syntax word (error) |
| `unknown-type` | Error | An unknown type for a `@define` parameter |
| `plugin-replaces-command` | Warning | A plugin command overrides a built-in command, or a command with the same name from a plugin loaded earlier (such as the standard commands), without declaring it (`replaces: true`) |
| `script-not-allowed` `script-skipped` | Error, warning | `@script` in a project without `allowScript` (error). Even in a project with it, the contents of `@script` don't run (warning; rewrite them as plugin commands) |
| `staff-roll-empty` | Warning | A `@staff-roll` with no content (chapter 5) |
| `html-tag-not-allowed` `html-attribute-not-allowed` `html-event-attribute` `html-dynamic-attribute` | Error | A tag that can't be used in `@html` (`<script>` and so on), an attribute that can't be used, an `on…` attribute, `{= expression}` in an attribute that can't take expressions (chapter 5) |
| `html-external-url` `html-empty-src` | Error | An external URL in `@html`, an empty `src=` |
| `html-unclosed-tag` `html-bad-nesting` | Error | An unclosed tag in `@html`, badly nested tags |
| `html-inline` | Error | `{@html …}` in text (`@html` is written on the lines up to `@end`) |
| `html-empty` `html-wait-without-jump` `html-jump-without-wait` | Warning | An `@html` with no content, `wait=true` without any element that jumps when pressed, `data-jump` without `wait=true` |

**Jump targets**

| code | Severity | Contents |
|---|---|---|
| `unknown-label` `unknown-file` | Error | An unknown label, an unknown file |
| `unknown-targets` | Warning | The candidates of a jump target decided by an expression can't be read, and there is no `to=` (chapter 8) |
| `all-options-conditional` | Warning | Every choice has `if=`, so none might be shown and the game might stop (chapter 8) |
| `unknown-option` | Warning | The choice with the text in `chosen("text")` isn't in any scenario (it's always false; chapter 8) |
| `call-without-return` | Warning | `@return` can't be reached from where `@call` goes (it stops at the end of the file and doesn't return to the caller). Not reported when it moves elsewhere with `@jump` or a choice on the way |
| `unreachable-line` | Warning, info | Lines without a label after `@jump`, `@return`, `@stop` or a command that ends the playthrough (they can't be reached from anywhere). A warning if the unreachable lines include dialogue, narration or choices, info if they're only commands |
| `unused-label` | Info | A label that's never jumped to and isn't continued into from the line before (the scene can't be reached). `"#label"` in expressions, `entry` and replays in liminalia.json, and targets in plugin data also count as jumps |
| `scene-start-no-bg` | Info | A scene (a label or the start of a file) reached from another file by `@jump` or a choice doesn't set the background (`@scene-change` or `@bg` with a background image, or a solid-color background) before its first text. It starts on the previous file's screen, which differs from playing it from that point. A `@scene-change` without an image (the template for scenes made in the Studio) doesn't count as setting the background. Not reported when every jump into it sets the background just before jumping (before the `@if` too, when jumping from inside one), or for `@call`, `call=true` choices, expression targets, and scenes that start with `@if` or a macro, draft files, and works that use no backgrounds |
| `unused-define` `unused-speaker` | Info | A macro that's never called, a speaker not used in any dialogue (shown on that speaker's line in `speakers` in cast.json; speakers listed in `check.unusedSpeakers` in liminalia.json are left out) |
| `draft-target` | Warning | A file that isn't a draft goes to a draft file (`// lim: draft`, chapter 10). Drafts aren't exported, so the check before `lim build` treats it as an error |
| `draft-use` | Error | A file that isn't a draft uses a draft file with `@use` (the exported game doesn't have that file's macros and functions) |
| `draft-entry` | Error | `entry` (New Game), `afterLoad`, or the `target` of a replay or chapter in extras in liminalia.json points to a draft file (the exported game stops there) |

**Characters**

| code | Severity | Contents |
|---|---|---|
| `unknown-cast` `unknown-appearance` `unknown-variant` `unknown-position` | Error | A character, sprite set, variant or position that isn't in cast.json |
| `unknown-tone` | Error | An unknown color tone |
| `bad-cast` | Error | A malformed cast.json (including a character's `side` other than `left` or `right`; chapter 6) |
| `cast-ambiguous` | Warning | The base variant or default sprite set falls to the order they're listed in (chapter 6) |
| `model-plugin-missing` | Warning | The plugin that draws a `model` type in cast.json (`live2d`, `spine`) isn't loaded and isn't in `plugins` in liminalia.json, or a close misspelling of a type (`Live2D`). The game shows the image sprite ([live2d-spine.md](../live2d-spine.md)) |
| `chara-reshow` | Warning | The same character is shown again after their sprite was hidden, with no text in between (it disappears and appears again, so it flickers). When hiding everyone and the show right after can be made one `@chara … clear=…` with the same effect, that's the suggested fix. Depending on the case, such as hiding a single character, a suggested fix that deletes the line that hid it is also given. Not reported when the sprite set changes, when the character moves in or out with `enter` `exit`, or with a background change, a fade to black, a movie or `@wait` between hiding and showing again (chapter 6) |
| `chara-hide-per-line` | Warning | Hiding everyone with `@chara-hide-all` and showing them again within every 2 lines of dialogue, 3 or more times in a row (chapter 6) |
| `chara-solo` | Info | `@chara` on the line right after an `@chara-hide-all` while someone is on stage. Comes with a suggested fix that makes them one line, `@chara … solo=true` (for fixing the one-at-a-time style all at once; `lim check --fix chara-solo`). Not reported when the hide-all has anything other than `time`, when the character moves in, when a character on stage is shown again with the position or variant left out, or when it can't tell whether the character is on stage (chapter 6) |

**Assets and project settings**

| code | Severity | Contents |
|---|---|---|
| `missing-asset` | Error | An asset file that doesn't exist |
| `asset-not-exported` | Warning | A reference to a kind of file that isn't exported (an extension not in the table of assets) |
| `redundant-cg-unlock` `unshown-cg` | Info, warning | A `@cg-unlock` that isn't needed because showing the CG unlocks it, a CG that no scenario shows or unlocks (it can't be seen in the extras) |
| `font-no-vertical-metrics` | Warning | The font for vertical text has no vertical advance widths (vmtx) |
| `asset-case-mismatch` | Error | An asset name differs from the file name only in upper and lower case (it opens on Mac and Windows but can't be read on Linux servers or phones). It's compared against the real names in the folder, and the suggested fix replaces it with that name |
| `lfs-pointer` | Error | A referenced asset is still a Git LFS pointer (its content hasn't been fetched, so it can't be shown or played). Reported at the first reference of each asset. The fix is `git lfs pull` (in CI, `lfs: true` on `actions/checkout`) |
| `missing-voice` | Warning | A voice file that doesn't exist (only for speakers with a single `@voice-auto` pattern) |
| `bad-config` | Error, warning | liminalia.json or cast.json can't be read as JSON (the line and column are shown), a mistake in a `variables` name or in the value of `saves.location` (that item isn't used; chapter 10), a malformed `check.sound` (a scene in `quiet` that doesn't exist is a warning; "Gaps in sound" below) |
| `unknown-config-key` | Warning | An item not in the schema in liminalia.json, cast.json or a translation file (it isn't used). The suggested fix is an item with a similar spelling (chapter 10) |
| `newer-format` | Warning | `format` in liminalia.json (the version of the script format) is newer than this engine's format version (a script written with a newer engine; "Script format versions" in chapter 10) |
| `bad-ui` `bad-items` `bad-extra` `bad-after-load` | Error | A malformed `ui` `items` `extra` `afterLoad` in liminalia.json |
| `unknown-nvl-style` | Error | The look name in `@nvl on style=` isn't in `ui.nvlStyles` in liminalia.json (chapter 4) |
| `bad-command-defaults` | Error | A mistake in `commandDefaults` in liminalia.json (an unknown command or parameter, a value of the wrong type; that value isn't used; chapter 5) |
| `bad-chapters` `chapter-files` | Error, warning | Malformed `chapters` in liminalia.json, a file pattern that matches no scenario, or a file in two chapters (chapter 10) |
| `bad-auto-layout` | Error | Malformed `autoLayout` in liminalia.json (a number of positions that doesn't match the number of characters, an unknown `enter` or `exit`, a `byCount` key that isn't a headcount or an empty name), or a position name that isn't in any sprite frame (the written side of `byCount` too; chapter 6) |
| `chapter-card-empty` | Warning | A `@chapter-card` or `@chapter-end` with no number or title in a script file that isn't in any chapter (a blank card appears; chapter 10) |
| `not-in-chapter` | Info | In a project that uses chapters, a script file reached from the start with text that isn't in any chapter (the chapter heading in save slots and `chapter()` are empty; chapter 10) |
| `unknown-item` | Error | An item that isn't in `items` |
| `not-in-extra` | Warning | A command that unlocks a name that isn't in the `extra` lists |
| `missing-translation` `bad-translation` | Warning, error | A translation file doesn't exist, or can't be read as JSON (the line and column are shown) |
| `translation-lost-command` `unused-translation` `stale-translation` | Warning, info | An inline command in the original text is missing from a translation, a translation is unused, translations of original text that's no longer in the scenario are left in `stale` |
| `untranslated` | Info | The number of untranslated items (items with an empty translation and items not yet in the translation file: text lines, choices, command text, project settings text) |
| `outdated-translation` | Info | The number of items whose original changed after translation (lines with a fixed line ID; the translation of the earlier original is shown). `lim i18n --export xliff --changed` exports them (chapter 10) |
| `voice-unlocked` `voice-lock-outdated` `voice-lock-duplicate` | Warning, error | Mistakes in locked voice numbers: a line with no number (it doesn't play), a number for a line that's no longer in the scenario, the same number given to more than one line (chapter 10) |
| `bad-voice-lock` | Error | voice-lock.json can't be read as JSON |
| `ui-css-missing` | Error | A file listed in `ui.css` (the work's CSS) in liminalia.json doesn't exist (shown on that line of `ui.css`) |
| `ui-css-syntax` | Error | The work's CSS can't be read (an unclosed comment, quote or bracket; shown on that line of that file) |
| `ui-css-asset` | Error | A file that a `url()` or `@import` in the work's CSS points to doesn't exist (looked up relative to the CSS file) |
| `ui-css-outside` | Error | A `url()` or `@import` in the work's CSS points outside the work (an absolute URL like `http:`, a path starting with `/`, or above the work's folder; it isn't exported and can't be read in the exported game) |
| `bad-rules` `bad-scenes` | Error, warning | Malformed `check.rules` and `scenes` in liminalia.json (see below) |

**Screen templates (`ui.templates`)**

Standard screen templates that a project copied and edited ([screen-templates.md](screen-templates.md)) are checked against the standard template and the rules of that screen (the part names, the values of `data-role` and `data-field`, and the `data-role` values the screen needs).
Problems in liminalia.json go on the line of that screen in `ui.templates`, and problems inside a template go on the line of that file.

| code | Severity | Contents |
|---|---|---|
| `template-missing` | Error | A file registered in `ui.templates` doesn't exist or can't be read (the standard screen is shown as is) |
| `template-unknown-screen` | Warning | A screen name in `ui.templates` isn't a screen that can be made with a template (it isn't used). Shows a name with a similar spelling, or the screens that can be made |
| `template-overridden` | Warning | A plugin's `screens.*` (also `system`, and the `screens.*` of the chosen theme) replaces the same screen, so the template isn't used. Only what can be read from how the plugin's `./web` is written is checked |
| `template-unknown-part` | Warning | A part name (`data-part`) in the template isn't in that screen, a `<template>` has no `data-part`, or the file has no parts and no `<style>` (it isn't used) |
| `template-unknown-value` | Warning | A value of `data-role`, `data-field`, `data-text` or `data-setting` does nothing in that screen (pressing does nothing, no text goes in). Shows a value with a similar spelling |
| `template-missing-role` | Error | A `data-role` the screen needs is missing (none of `close`, `cancel` and `ok` to close it, no `ok` in the confirmation screen, and so on). Checked on the whole screen, with the project's parts placed over the standard parts |
| `template-list-item` | Error | A `data-list` in a part has no `data-item`, or the `data-item` part doesn't exist (the rows of the list can't be made) |
| `template-unsafe` | Warning | The template has something the game removes at run time (elements such as `script`, attributes starting with `on`, outside URLs, links to other pages, `@import`), so it doesn't work |
| `template-outdated` | Warning | The version a part was copied from (its `data-version`) is older than the standard's current version, or has no version (the standard template changed). Shows the part name and the standard's current version, and points to `lim screens diff <screen>` |
| `template-script-export` | Warning | The screen JS (the `.js` next to the template with the same name; `ui/screens/<screen>/<screen>.js` when no template is registered) has no `export default` (it does nothing when loaded) |
| `template-script-unknown` | Warning | The screen JS uses something the screen `api` doesn't have (such as `api.answer`), or an `api.press` value that does nothing in that screen. Only checked when the parameter is named `api`. Shows a similar name |

**Project data (data declared by plugins)**

Project data whose shape a plugin declares (the .json files in `paths.data`; docs/plugins.md) is checked against the declaration.

| code | Severity | Contents |
|---|---|---|
| `data-missing` `data-type` `data-duplicate` | Error | A required item is missing, a value has the wrong type, the same id appears twice |
| `data-bad-expr` | Error | A condition expression in the data can't be read |
| `data-missing-asset` `data-unknown-cast` `data-unknown-scene` `data-unknown-ref` | Error, warning | An asset, character, scene or other item referred to in the data doesn't exist |
| `data-flag-unset` `data-flag-unread` | Warning, info | No script or data sets a flag the data reads, nothing reads a flag the data sets |
| `unknown-data-key` | Error | The value of a plugin command's data-name parameter (`t.dataKey`) isn't in the project's data (also when the data file doesn't exist, or when the path the parameter reads isn't in the file) |
| `unknown-investigation` `unknown-codex-entry` | Error | The name for a standard investigation (`@investigate`) or codex (`@codex-unlock` and so on) isn't in the project's data (`data/investigation.json`, `data/codex.json`). Also when a view or section name doesn't exist. Found while running, it's a runtime diagnostic (a warning for the codex) |
| `map-spot-hidden` | Warning | The middle of a spot's press area on a map choice screen (`@map-choice`) is under the details panel (`panel`), so it can't be pressed. Move the spot out from under the panel, or put `panel` on a side that doesn't cover it |

**Plugins**

| code | Severity | Contents |
|---|---|---|
| `plugin-load` | Error | A project plugin can't be loaded (the package doesn't exist, a syntax error and so on; the reason is given). Studio and `lim studio` open without that plugin, and reports that its commands are undefined are gathered into the hint of this diagnostic |
| `plugin-check-failed` `plugin-check-invalid` | Error | A plugin's `check` threw, or returned something that isn't an array of diagnostics or diagnostics with the wrong shape (the other checks run to the end) |
| `plugin-api-version` `plugin-engine-version` | Warning | A plugin uses a newer interface version than this engine (`apiVersion` of `defineCommandPlugin`, and `liminalia.api` and `engines.liminalia` in `package.json`; "Declaring compatible engines" in [plugins.md](../plugins.md)) |
| `theme-engine-version` | Warning | `engines.liminalia` of a theme in the project (`themes/<id>/theme.json`) doesn't match this engine's interface version (some of the look may not show) |
| `engine-version` | Warning | `engines.liminalia` in `liminalia.json` (the engine interface versions the game or template works with) doesn't match this engine |
| `plugin-function-clash` | Warning | A plugin's expression function has the same name as a built-in function, so it isn't used |

### Invisible characters (`invisible-space`)

Invisible characters aren't read as separators and become part of a command or name, causing mistakes that are hard to find, so they're warned about.

| Character | Where it's warned about | Suggested fix |
|---|---|---|
| Zero-width characters (U+200B and so on), BOM | On any line | Delete it |
| Spaces that don't act as separators, such as the no-break space and the full-width space | Command and label lines (except inside `"…"`), and from the jump target of a choice onward | Replace it with a half-width space |

### Punctuation (brackets, periods and commas, symbols)

These checks are for Japanese punctuation (full-width brackets and marks), so the examples are in Japanese.
The punctuation of dialogue, narration and choice text is checked line by line, using the characters that are shown (the base text of ruby, without inline commands).
Turn off checks that your game's writing rules don't need with `check.punctuation` in liminalia.json (`false` turns off all of them, and `{ "off": ["single-ellipsis"] }` only the ones listed).

| code | Severity | Contents |
|---|---|---|
| `bracket-mismatch` | Warning | A missing closing or opening bracket among 「」『』（）【】, or mismatched nesting (counted within one line) |
| `doubled-punctuation` | Warning | The same punctuation mark twice in a row (`。。` `、、`). The suggested fix makes it one |
| `space-after-exclamation` | Info | No full-width space after `！` `？` in the middle of a sentence (not needed before a closing bracket, a following `！？`, `…` `―` or the end of the line, or when followed by a quoting particle such as 「と」 or 「って」, as in `都会！ってこと`). A half-width space is changed to a full-width one. Each one in a line is reported, and "Fix all" fixes them all |
| `single-ellipsis` | Info | `…` or `―` written only once (write two, as `……` `――`) |

```json
"check": { "punctuation": { "off": ["space-after-exclamation"] } }
```

`space-after-exclamation` and `single-ellipsis` are rules of Japanese typesetting, so they're checked only in projects whose source language (the first entry of `languages` in liminalia.json; Japanese if there is none) is Japanese. `Wait…` in an English project isn't reported. This isn't decided line by line by whether the line contains Japanese characters (in a Japanese project, a line that's only `…` contains no Japanese characters, yet it's exactly the line to fix). Mismatched brackets and doubled punctuation are mistakes, so they're checked in projects in any language.

### Staging rules (`check.rules`) and scene information (`scenes`)

If you declare your project's staging rules in liminalia.json, the syntax check (`lim check`, and the check in Studio) checks them.
It reads the scenario from the top and follows the state of sprites and fades to black (each branch of `@if` is followed and merged, and a label that isn't reached by continuing from the line before starts empty, because its state is unknown).

```json
"check": {
  "rules": [
    { "rule": "cg-without-sprites" },
    { "rule": "fade-before-file-jump", "commands": ["mask", "scene-change"] },
    { "rule": "no-pov-sprite" },
    { "rule": "appearance-era", "eras": { "past": ["young*", "mourning", "childhood"] } },
    { "rule": "appearance-change-while-shown", "severity": "info" }
  ]
},
"scenes": {
  "chapter2_3": { "pov": "Yuika", "date": "8/12", "place": "Shrine" },
  "chapter2_3#night_talk": { "pov": "Haru" }
}
```

| Rule | code | What it reports |
|---|---|---|
| `cg-without-sprites` | `rule-cg-with-sprites` | Sprites are still on screen when a CG (an image in extra.cg) is shown |
| `fade-before-file-jump` | `rule-fade-before-jump` | No fade to black before a `@jump` to another file (`commands` are the commands counted as fading to black; the default is `mask`, `scene-change`. The screen stays covered until `@mask-off`) |
| `no-pov-sprite` | `rule-pov-sprite` | A sprite of the scene's point-of-view character (`pov` in `scenes`; a character ID or speaker name) was shown. `allow` lists the sprite sets that may be shown |
| `appearance-era` | `rule-appearance-era` | Sprite sets from different eras were mixed. `eras` maps an era → sprite set names (`*` matches any characters). In scenes with an era in `scenes` (`field`, default `era`), characters who have a sprite set for that era must use it. In scenes without an era, it reports eras mixed within one label |
| `appearance-change-while-shown` | `rule-appearance-change` | The sprite set of a character on screen was changed without hiding them (change outfits by hiding the character and showing them again) |

- Every rule can have `severity` (`error`, `warning`, `info`; default `warning`) and `message` (text in your game's own words)
- `scenes` maps `file` or `file#label` → scene information. If a label has no information, the file's is used. Besides `pov`, `date` and `place`, you can write your project's own items (`era` and so on). Pointing to a scene that doesn't exist is a warning (`bad-scenes`)
- Things a machine can't see (acting through expressions, outfits described in narration, how an identity is revealed, and so on) aren't made into rules
- To make an exception to a rule on one line, write `// lim-ignore rule-pov-sprite` before that line (see "Silencing diagnostics" below)

In Studio, "Scene info" in the menu of a scene in the scene list and of a card in the flowchart edits `pov`, `date` and `place` for that scene
(the key is `file` for the scene at the top of a file and `file#label` for a labeled scene). The rules are chosen under Check in the project settings.

### Silencing diagnostics (`lim-ignore` and `check.severity`)

Warnings and info that are exceptions on a line, or that a project doesn't need, can be hidden. Errors are never silenced or changed.

```
// lim-ignore rule-pov-sprite
@chara Yui smile
```

- `// lim-ignore code…` applies to the next line (comment lines in between are skipped). Separate codes with spaces or `,`. Without a code, it hides every warning and info on that line
- `// lim-ignore-file code…` applies to the whole file
- It can't go at the end of a line (a trailing `//` becomes text; chapter 2). Write it on the line before, for commands and dialogue alike

To change the severity of a code for the whole project, write it in `check.severity` in liminalia.json (`error`, `warning`, `info` or `off`; `off` hides it).
Making a warning an `error` makes `lim check` fail (for things CI should stop on). Only warnings and info can be changed.

```json
"check": { "severity": { "single-ellipsis": "off", "unused-label": "warning" } }
```

Diagnostics for cast.json point at the line of the item (an unused speaker at that speaker's line in `speakers`, a malformed character, a missing sprite or a `model` with no plugin at that character's line).
JSON can't hold comments, so to silence an unused speaker (`unused-speaker`) one speaker at a time, list the names in `check.unusedSpeakers` in liminalia.json
(characters a later part of the story uses, and so on). A name that isn't in `speakers` gets a warning (`bad-config`).

```json
"check": { "unusedSpeakers": ["Kai", "Mina"] }
```

In Studio, the menu of a problem tooltip (the squiggles in the code view) and of a row in the Check list has "Don't show on this line" (writes `// lim-ignore code` on the line before)
and "Don't show this kind" (writes `off` in `check.severity`). To undo, delete the comment line, or choose the level again under Check in the project settings.

| code | Severity | Contents |
|---|---|---|
| `unused-ignore` | Info | A `lim-ignore` that silenced nothing (no warning or info with that code on the next line or in the file, a misspelled code, or an attempt to silence an error). With a fix that deletes the line. Reported only when the whole project is checked, as in `lim check` and the Check screen in Studio |

### Merging into a scene change (`scene-change-candidate`)

Blocks from `@mask` to `@mask-off` that meet these conditions are reported as info, with a fix that turns them into one `@scene-change` line (Fix all fixes them at once).

- The block contains only `@bg`, `@chara-hide-all`, `@stop-bgm` and `@bgm` (each at most once), including `@bg` or `@chara-hide-all`, with no blank or comment lines
- `@mask` has only `time`, `color` and `hide-window`, and `@mask-off` only `time` (fades with a method or a rule image aren't replaced). A fade to a color other than black
  (a white flash and so on) is usually not a scene change, so it isn't replaced
- `@stop-bgm` and `@bgm` come right after the fade-out, before any command that waits while covered. `@bgm` has only `time` and `volume`. Blocks that stop and then change the BGM aren't replaced
- A block without `@chara-hide-all` is replaced only when the earlier lines of the same flow are known to have hidden every sprite without showing one again (`@scene-change` hides every sprite).
  The same goes when a non-waiting `@chara-hide-all` is still fading out when the fade-in starts
- A line that hides everyone followed right away by `@scene-change`, or lines that hide everyone followed by `@mask`, `@wait` and `@mask-off`, are merged, when the conditions are met, into one line with `hide-chara-at=start`, which hides the sprites as the fade-out starts. The `@wait` time goes into `hold`, and the hiding time into `hide-fade`. As with the original `@mask`, the message window still disappears once the screen is fully covered
- A line that hides a particular character followed right away by a `@scene-change` that hides only that character is also merged into one line when the conditions are met. If the original scene change hides everyone, they aren't merged, because who stays on screen would change

The replacement uses `time` for the fade-out and fade-in (`fade-out` and `fade-in` when they differ), `hold` for the time covered by waiting `@bg` and `@chara-hide-all`,
`bgm`, `bgm-volume` and `bgm-fade` for `@bgm`, and `stop-bgm=true` and `bgm-fade` for `@stop-bgm`, and copies `hide-window` from `@mask`.
Values are read with the project defaults (`commandDefaults`) applied, and values equal to the default of `@scene-change` aren't written.
Fades that aren't scene changes (a pause, putting a haze on and off, and so on) can stay as `@mask` (silence them with `// lim-ignore scene-change-candidate`).

When the previous sprites are still disappearing into the fade-in, `scene-change-sprite-overlap` warns about it, with a fix that turns it into a `@scene-change` that hides them while covered and then fades in. Fixing it changes when the sprites disappear. If it's the effect you intended, use `// lim-ignore scene-change-sprite-overlap`.

### Gaps in sound (`check.sound`)

Whether BGM and ambient sounds (`@se` with `loop=true`) are playing is followed along the flow of the script (`@jump`, `@call`, choices, lines that continue into a label, the inside of macros),
and gaps and stops that do nothing are reported (`lim check`, the check in Studio, VS Code). Every branch can be seen without running, so this is done by the syntax check rather than by `lim coverage`.

| code | Severity | Contents |
|---|---|---|
| `long-silence` | Warning | `check.sound.silence` lines (default 30) or more of text (dialogue and narration) go on with neither BGM nor an ambient sound playing. Reported on the line where counting started, with the number of lines and the last line. Time paused with `@pause-bgm` and one-shot `@se` count as silence |
| `redundant-stop` | Info | Stopping something that isn't playing (`@stop-bgm`, `@scene-change stop-bgm=true`, `@stop-se`). The suggested fix deletes the line (for `stop-bgm=true`, the argument) |
| `loop-across-files` | Info | A looping sound effect started in another file keeps playing in the text of a file reached by `@jump` or a choice (carrying the sound of rain into the next scene because you forgot to stop it, and so on). Reported on the first text of the destination, with the line that started it and the channel |

```json
"check": {
  "sound": {
    "silence": 40,
    "quiet": ["epilogue", "chapter3#dream"],
    "carry": ["ambience/cicadas.ogg"],
    "off": ["redundant-stop"]
  }
}
```

- `silence` is the number of text lines before it's reported (an integer of 1 or more; default 30). `quiet` lists scenes where the sound is cut on purpose (`file` or `file#label`), and text inside them isn't counted (pointing to a scene that doesn't exist is a warning).
  `carry` lists looping sound effects that may keep playing across files (paths from sound). `off` lists the codes of diagnostics to turn off. `"sound": false` turns them all off. A malformed value is `bad-config`
- It reports only when the result is the same whichever way the flow came. Sounds played on only one side of a branch, and places where whether a sound plays depends on the path taken, such as `@bgm` inside `@if`, aren't counted from (it errs on the side of not reporting by mistake)
- Starting with nothing playing are "New Game" (`entry`) and replays and chapters in the extras (`target` of `extra.replay` and `extra.chapters`).
  `afterLoad` and scenes that nothing jumps to start in a state where what's playing is unknown
- A macro is followed inside, at the place it's called (the parameter values are read too). A stop inside a macro depends on where it's called, so it isn't reported as doing nothing.
  Where `@call` goes continues as is if the sound doesn't change before `@return`, and if it does change, that sound becomes unknown. After `@awake-game` and `@rollback`, it's unknown
- Plugin commands with a BGM asset parameter make the BGM unknown, and those with a sound effect asset and `loop` make the sound effects unknown.
  Targets declared with `targets` are entered with the sound at the point of that command

### Runtime diagnostics

What the syntax check can't find, and only running shows, becomes a runtime diagnostic. You can find them with `lim coverage` and on Studio's Check screen.

- Keeping values you didn't write in `@chara` led to a combination that doesn't exist (changing only the outfit when that outfit doesn't have the current expression, and so on)
- Every `if=` was false, so no choice was shown (`no-choice-shown`)
- A jump was attempted to a target that isn't in `to=`
- The expression of a condition gave an error (the condition is treated as false)

When running (test play, the all-routes test, `lim coverage`, `lim trace`), syntax errors in the files read are reported too. But style suggestions
(`chara-reshow` `chara-hide-per-line` `same-as-default` `scene-change-candidate`) and info aren't, since they don't change how the game runs (the syntax check reports them).

| code | Severity | Contents |
|---|---|---|
| `runtime` | Error | An error while running (a type mismatch in an expression, a sprite combination that doesn't exist, a target not in `to=`, and so on). An error in a condition's expression makes that condition false |
| `no-choice-shown` | Warning | Every `if=` of the choices was false, so no choice was shown |
| `unsupported-command` `script-skipped` | Warning | A command that doesn't run in that environment (such as a command that only draws, when running without a screen), an `@script` that was passed (its contents don't run) |
| `unknown-screen` | Warning | The screen to open (`@open-screen` and so on) doesn't exist |
| `save-version` `save-relocated` | Error, warning | A save that can't be loaded (a save version newer than this game's, or a broken save; "Save versions" in chapter 10), a save position that shifted because the scenario changed (it resumed from a nearby line) |
| `target-never-offered` | Warning | A target declared by a plugin command never appeared as a choice when run without a screen (`lim coverage`) |
| `choice-loop` | Warning | When run without a screen, the flow kept coming back to the same choice with no text in between, so it was stopped (`lim trace`; add a choice that leads out, or choose with `--choose`) |
| `emote-hidden` | Warning | The character of `@emote` isn't shown, so no emote was added |
| `unknown-map` `empty-map` | Error, warning | The map of `@map-choice` isn't in `maps` of `data/investigation.json`, there's no spot to choose (it moves on to the next line) |

## 10. Project files

| File | Contents |
|---|---|
| `liminalia.json` | Placed directly in the project folder. The items are in `packages/project/src/index.ts` |
| `cast.json` | Speakers and characters (sprite definitions) |
| `voice-lock.json` | Locked voice numbers (`paths.voiceLock`) |
| `lang/<language>.json` | Translations |

Asset paths are checked for existing files by the syntax check before exporting.

**Mistakes in the settings JSON.** If `liminalia.json`, `cast.json` or `lang/<language>.json` can't be read as JSON, the line and column where it can't be read are shown with a message that explains it
(`liminalia.json:5:1 Can't read it as JSON: There can't be a , after the last item` and so on; it tells apart a trailing `,`, a missing `,`, comments and `'…'` strings. `bad-config`, `bad-translation`).
A mistake in a `variables` name or in the value of `saves.location` in `liminalia.json` doesn't stop everything; only that item isn't used, and the syntax check treats it as an error (`bad-config`).
Items not in the schema aren't used even if written, so they're warned about, with an item with a similar spelling as the suggested fix (`unknown-config-key`; inside `ui`, `bad-ui` checks).
Mistakes in the shape of a value (`bad-ui`, `bad-chapters`, `bad-extra`, `bad-command-defaults`, `bad-config` for `check.sound` and so on) are shown on the line of the item with the mistake
(found by the settings path in the message, such as `ui.window.padding`, by `@command parameter`, or by the character name; if it isn't found, the first line of that item).
In `cast.json`, an unused speaker is shown on that speaker's line in `speakers`, and a missing sprite or a `model` with no plugin on that character's line.
When `voice-lock.json` can't be read as JSON, the line and column where it can't be read are shown too (`bad-voice-lock`). Studio's check shows the same, and
for a script that can't be read as UTF-8, only `bad-encoding` is shown (no diagnostics from the garbled content).

The list of items is available as JSON Schema (`liminalia.schema.json`, `cast.schema.json` and `lang.schema.json` in `packages/project/schemas`,
made from the types `ProjectConfig`, `CastEntry` and `TranslationFile` with `npx tsx packages/project/scripts/config-schema.ts`). The VS Code extension
applies them to `liminalia.json` and `cast.json` and shows completion and descriptions of the items. They're also on the site at `https://liminalia.skyta.dev/schemas/<name>.schema.json`.
`lim new` writes `"$schema"` with that URL at the top of `liminalia.json` and `cast.json`, and `lim i18n` does the same for translation files it creates (so other editors and AI assistants can look up the items too).
For a project made earlier, write `"$schema": "https://liminalia.skyta.dev/schemas/liminalia.schema.json"` and so on at the top of the file.

### Drafts (`// lim: draft`)

Writing `// lim: draft` in the comments at the top of a file makes it a draft.

```
// Chapter 3, unfinished
// lim: draft
# start
……
```

- It isn't exported (`lim build`), and doesn't count in the players' flowchart (`flow.json`) or the automatic CG list (`extra.cgAuto`)
- The all-routes test (`lim coverage`, Studio) doesn't run it and it doesn't count toward coverage
- Unreachable lines and unused labels (`unreachable-line`, `unused-label`) aren't reported
- The syntax check runs on it like any other file. The check before `lim build` doesn't count the diagnostics in drafts
- A line in a file that isn't a draft that goes to a draft is a warning (`draft-target`), and an error in the check before `lim build`
- A file that isn't a draft using a draft with `@use` is an error (`draft-use`). So is `entry`, `afterLoad`, or the `target` of a replay or chapter in extras in liminalia.json pointing to a draft (`draft-entry`), because the exported game stops there. In Studio, the `entry` file can't be marked as a draft
- It can be played in test play (`lim dev`, Studio)

The scene list in Studio shows "Draft" next to the file name, and "Mark as draft" and "Unmark as draft" in the file menu rewrite the mark at the top.

Drafts aren't a folder (`scenario/drafts/`) because moving a finished file out of the folder changes its name (the jump target `drafts/…`),
and every line pointing at it would have to be fixed. With a mark, the file name and change history stay the same.

### cast.json

```json
{
  "speakers": ["Yui", "Ren", "???"],
  "cast": {
    "Yuika": {
      "defaultAppearance": "uniform",
      "appearances": {
        "uniform": {
          "label": "Uniform",
          "variants": {
            "normal": {
              "image": "chara/yuika/uniform_normal.png",
              "frame": { "width": 440, "height": 680, "positions": { "left": { "left": 60, "top": 40 }, "center": { "left": 420, "top": 40 }, "right": { "left": 780, "top": 40 } } }
            },
            "smile": {
              "image": "chara/yuika/uniform_smile.png",
              "frame": { "width": 440, "height": 680, "positions": { "left": { "left": 60, "top": 40 }, "center": { "left": 420, "top": 40 }, "right": { "left": 780, "top": 40 } } }
            }
          }
        },
        "casual": {
          "label": "Casual",
          "variants": {
            "normal": {
              "image": "chara/yuika/casual_normal.png",
              "frame": { "width": 460, "height": 700, "positions": { "left": { "left": 50, "top": 20 }, "center": { "left": 410, "top": 20 }, "right": { "left": 770, "top": 20 } } }
            }
          }
        }
      }
    },
    "Ren": {
      "appearances": { "default": { "variants": { "normal": { "image": "chara/ren/normal.png" } } } }
    }
  }
}
```

The shape is the same as tatie's settings (`characters` in `settings.js`), except that a variant's image is written as `image` instead of `storage`.

**What to write for a character**

| Item | Contents |
|---|---|
| `appearances` | Sprite set name → `{ label, variants, layers, face }`. `label` is a name for display (optional). For a character without sprites (a speaker who only sets a name color, and so on), `{}` is fine |
| `defaultAppearance` | The default sprite set (optional) |
| `color` | Text color in the name box (a CSS color; optional). The color of the character whose ID or `speaker` matches the speaker name of the dialogue is used |
| `text` | How this character's dialogue text looks (optional). `{ "color": "#e8b4c8", "font": "Georgia, serif", "italic": true }`. Omitted items use the project's defaults. It also applies to the text in the backlog. Styling in the text such as `{c …}` comes first, and so do the read-page color (`ui.text.readColor`) and the font the player chose |
| `nameImage` | Name box image while this character speaks (a path from `image`; optional). `ui.name.image` if omitted |
| `windowImage` | Message window image while this character speaks (a path from `image`; optional). `@window-image` comes first. `ui.message.image` if omitted |
| `speaker` | The speaker name in the text. Write it when it differs from the character ID (it ties lip sync and the name color to the speaker) |
| `side` | The home side in the automatic layout by order of appearance (`left` or `right`; optional; chapter 6) |
| `lip` `blink` | Overlay images for lip sync and blinking (see below) |

**What to write for a variant (inside `variants`)**

| Item | Contents |
|---|---|
| `image` | A path from `assets/fgimage/` |
| `frame` | Position and size. `width` / `height` are the displayed size (px; 632×843 if not written). `positions` maps position names → `{ left, top }` (top-left coordinates). `flipAxis` is the axis the picture is mirrored around when the sprite is flipped (optional; see below) |
| `parts` | Written instead of `image` for layered sprites (see below) |
| `face` | The picture for the face window (a path from `assets/fgimage/`) |
| `cacheKey` | No need to write it (see below) |

Rules for `frame`:

- `left` `center` `right` exist even if you don't write them; if not written, they're (0, 0).
- `auto` is a reserved name and isn't written in `positions` (chapter 6).
- A variant without `frame` is shown at the image's actual size, and its only named position is `center` (bottom center of the screen). Use it for sprites placed automatically (`at=auto`) or by coordinates (`x` / `y`).
- `flipAxis` is the axis used when the sprite is flipped with `@chara … flip=true`, written as an X from the image's left edge (image px). If it isn't written, the picture is mirrored around the image's center (the picture is mirrored inside the frame, so the frame's position doesn't change).
  Whatever lies on the axis (such as the chin) stays in the same place when flipped. Studio's "Match head size" writes this value for the variants it aligns (not for the reference variant), so the chin doesn't shift sideways between variants when they're flipped.

**Cache**: Export (`lim build`) writes a hash of each asset's content to `project/assets.json`, and the game adds it to the asset's URL.
Images and sounds replaced under the same name aren't shown from an old cache. During development (`lim dev`, Studio), assets are checked again and returned every time.
If there is a `cacheKey`, it's added to the URL too (the Characters screen changes it only when an image is overwritten under the same name, for the preview that's open).

**Lip sync and blinking (`lip` `blink`)**

- Overlay images of the same size as `image` with only the mouth or eyes drawn.
- List `lip` as slightly open mouth → wide open mouth, and `blink` as half-closed eyes → closed eyes.
- The mouth moves with the volume of that character's voice while it plays, or, when no voice is playing, only while the characters of that character's page are appearing.

**Layered sprites (`layers`)**

- In a sprite set, write the list of layers stacked from the bottom: `{ name, options: { picture name: image }, default }`.
- A variant writes `parts` (layer name → picture name; `""` hides that layer) instead of `image`. Layers not written use `default` (if there is none, they aren't shown).
- The game builds a single picture with the layers stacked before showing it, so changes, position and size are handled the same as for a single image.
- Draw the layer pictures at the same size (they're stacked with their top-left corners aligned).
- You can make them from PSD and PSB files with `lim psd` (chapter 12).

**Face window (`face`)**

- Written in a variant, it's that picture (a path from `assets/fgimage/`).
- Written in a sprite set, it's the area `{ x, y, width, height }` (px) cut out of the sprite (after stacking, for layered sprites).
- The variant's picture takes priority. A character with neither has no face window.

**Sprites drawn by a plugin (`model`)**

- A sprite that a plugin draws instead of an image (`{ "type": "live2d", … }`; everything other than `type` is read by that plugin).
- `image` becomes the still image that decides the position and size. How it's drawn is in the plugin's `extensions.spriteParts` ([plugins.md](../plugins.md)).
- A `model` written on the character applies to every variant. A `model` of the same `type` written on a variant is laid over the character's `model` (for a different `type`, only the variant's is used).
- `sway` (sways a single image) is built in. With the official plugins installed, `live2d` (Live2D Cubism) and `spine` (Spine) can be used too ([live2d-spine.md](../live2d-spine.md)).

**Importing from TyranoScript**: `lim import` builds it from `[chara_new]` / `[chara_face]`. There is one sprite set, `default`,
and the variant `default` is the `storage` of `[chara_new]`. `width` / `height`, if present, become the `frame`. If there are tatie settings
(`data/others/plugin/tatie/settings.js`), they're layered on top, and for the same sprite set and variant, the tatie settings win.

### Script format versions (format)

```json
{ "id": "my_game", "title": "My Game", "version": "1.0.0", "format": 4, "entry": "start" }
```

- `format` is the version of the format the scripts (.lim) are written in. `lim new` writes the current version. A project without it is treated as having scripts from before versions were written (1).
- When the engine changes the format (renaming commands and so on), the version goes up by one, and `lim migrate` gets a path that moves the earlier way of writing to the current one.
  The syntax check reports lines written the earlier way, with a replacement in the current way as the suggested fix (`renamed-command`, `renamed-param`).
- If `format` is newer than the engine's format version, the syntax check warns (`newer-format`; a script written with a newer engine is being checked with an older engine).

| Version | What changed |
|---|---|
| 1 | Scripts from before versions were written |
| 2 | Removed the command names of the earlier version: `@show` → `@chara`, `@hide` → `@chara-hide`, `@hide-all` → `@chara-hide-all`, `@sprite-config` → `@chara-config`, `@scene` → `@scene-change` (the arguments stay the same) |
| 3 | `ending=` of commands that end the playthrough became the kind of ending instead of on-screen wording, with the name moved to `title=`: `ending="BAD END"` → `ending=bad`, `ending="Passing Shower"` → `ending=other title="Passing Shower"` ("The end of a playthrough" in chapter 2). The format 2 way keeps working, and the syntax check reports it as `legacy-ending` |
| 4 | The time an action takes moved from `fade=` to `time=` (`@bg`, `@chara`, `@chara-hide`, `@chara-hide-all`, `@mask`, `@mask-off`, `@bgm`, `@stop-bgm`, `@se`, `@stop-se`, `@scene-change`, `@window`, `@image`, `@particles`, `@html` and others, 36 commands in all). `@effect`, `@effect-off`, `@staff-roll`, `@flash`, `@chapter-card` and `@chapter-end`, which already use `time=` for something else, keep `fade=`, as do `fade-in`, `fade-out`, `crossfade`, `hide-fade`, `bgm-fade`, `filter-fade` and `auto-fade`. `fade=` from format 3 and earlier keeps working, and the syntax check reports it as `renamed-param`. Commands without a target (`@chara-hide-all`, `@mask`, `@mask-off`, `@stop-bgm`, `@stop-se`, `@stop-voice`, `@stop-bg-movie`) also read an unnamed time as `time` (`@mask 600ms`) |

**`lim migrate`**

```
lim migrate              # Moves the scripts to the current format and rewrites them
lim migrate --check      # Doesn't rewrite; fails if there's anything to move (CI)
lim migrate --json       # The moved lines as JSON
lim migrate --keep-behavior               # Also writes settings that keep the old behavior where the default look or behavior changed
lim migrate --keep-behavior chara-swap    # Only the ones you choose (separate names with commas)
```

- In commands at the start of lines (`@scene …`) and inside text (`{@show …}`), command names, and parameter names that changed in script format 4, are changed to the current names. The contents of `@script`, `@html` and `@staff-roll`, and comment lines, aren't changed.
- If the project has a macro with the same name (`@define scene(…)`, the scene-change macro of the earlier template), that name isn't changed (it's working as the project's macro).
  A macro can be called only in the file that defines it and in files that `@use` that file, so built-in commands with the same name in other files are moved.
- Scripts in packs (`packs/*/scenario`) and `import.ink.commands` and `import.yarn.commands` in `liminalia.json` (the command templates for imports) are moved too.
- For lines whose original text changed because a command inside the text was rewritten, translations (for lines with a line ID the key stays the same, so the translation's source and the commands in the translation are rewritten)
  and voice number locks (keys and source in `voice-lock.json`; the numbers stay, and they aren't marked for re-recording) are moved too. Read marks come from the original text, so moved lines go back to unread for players of the version before migrating.
  Lines in pack scripts are moved the same way. A pack's translations (`packs/<id>/lang/*.json`) replace the whole translation for that language when the pack is installed, so the lines of both the main scripts and the pack scripts are moved in them. Voice number locks for pack dialogue are moved in the project's `voice-lock.json` (packs don't have their own). When the main project and a pack have a script with the same name and only one of them is migrated (for example, because only that script can call a macro with the same name as a built-in command), the translation and voice lock keys that the unmigrated script still uses are kept, and the new keys are added (a pack's translation keeps only the keys used when the pack is installed).
- Earlier names in `commandDefaults` in liminalia.json are changed to the current names too (if the current name is also set there, the unused earlier name is removed), and `format` is set to the current version (if `format` is the only thing to move, only the `format` line is rewritten, or added if it isn't there, and nothing else is changed).
- The formatting settings used up to 0.1.17 (`"format": { "indent": 2, "expressions": false }`) are moved to `fmt` before `format` is set to the current version (if `fmt` exists, only the missing keys are moved).
- Wording in `ending=` of commands that end the playthrough is moved to the kind and `title=`. Wording that tells the kind (BAD END, GOOD END, TRUE END, NORMAL END, with variants in case, ENDING,
  full-width letters and katakana) becomes the kind only; other wording becomes `other` with the wording in `title=`. Wording that starts with a kind and goes on (`BAD END 2: Silence`) is split into the kind and the rest in `title=`,
  with a note to check it. If the earlier wording differs from the kind's default wording (`Bad End`), it's written to `endingKinds` so the screen keeps the same wording (only when each kind is spelled one way).
- Wording in `playtest.avoidEndings` (`BAD END`, `BAD`) becomes the kind too. In translation files (`lang/*.json`), translations of the moved wording go to the `title=` key for names,
  and for a kind's wording to the key of the `endingKinds` wording (project settings text) or to `ending.kinds.<kind>` in `ui` (only translations that differ from the default wording); keys no longer used are removed.
- If a script can't be read as UTF-8, it stops without rewriting the other scripts or liminalia.json (also with `--check`; save it again as UTF-8 in an editor, then migrate).
  `lim fmt`, `lim rename`, `lim i18n`, `lim prose` and the other commands that rewrite the project do the same.
- It lists the changes to the default look or behavior since the project's format version (the "action needed" items in CHANGELOG) that concern the project. With `--keep-behavior`,
  for those a setting can undo, it writes that setting to liminalia.json (settings the project has already decided aren't written). For those a setting can't undo, it shows steps to get closer to the old behavior.
  After migrating, the project is in the current format and the list isn't shown anymore, so add the flag when you migrate if you want to keep the old behavior.

| Name | Changed in | What changed | Setting for the old behavior |
|---|---|---|---|
| `line-break` | 0.1.18 | Japanese and Chinese text wraps with `strict` | `ui.text.lineBreak: "auto"` |
| `chara-swap` | 0.1.18 | When characters swap in the same position, the previous one leaves first | `commandDefaults.chara.swap: "cross"` |
| `chara-keep-text` | 0.1.18 | During `@chara` with `wait=true`, the previous speaker's name box and text are cleared | `ui.chara.keepText: true` (since 0.4.1, `page-keep-text` is needed too) |
| `movie-skip` | 0.1.18 | A first-time `@movie` plays even during skip | (A setting can't undo it; write `skip=true`) |
| `voice-overlap` | 0.1.18 | Two `@voice` lines with different speakers or channels play at the same time | (A setting can't undo it) |
| `bgm-filter` | 0.1.18 | `@bgm` for the same track sets the filter again | (A setting can't undo it) |
| `choice-position` | 0.1.21 | Choices move to a height that doesn't cover the sprites' faces (projects that set `ui.choice.y` stay as before) | `ui.choice.position: "center"` |
| `ending-card` | 0.1.21 | Ending with `ending=` shows the ending's name and waits for a press (only projects with endings) | `commandDefaults.title-screen.card: "false"` |
| `ending-font` | 0.2.0 | The ending name's font follows the text font (only projects that set `ui.text.font`) | The old Mincho stack in `ui.ending.font` |
| `system-colors` | 0.2.0 | The colors of confirmation and input dialogs and of notices follow the colors in `ui.system` (only in projects that write colors in `ui.system`) | (A setting can't undo it; set them in the project's CSS) |
| `page-keep-text` | 0.4.1 | After a click turns the page, the first command clears the previous page's name and text | `ui.message.keepText: true` |
| `reduce-motion` | 0.5.0 | The "Screen effects" (standard / reduced) setting was removed, and text effects, `@effect` and the like always move | (A setting can't undo it; remove the branches that use `ctx.reduceMotion` and `lm-reduce-motion`) |

The format version became 2 in 0.1.18, 3 in 0.2.0 and 4 in 0.6.0. The changes in 0.1.19 to 0.1.21 came in while the format version was still 2, so they're listed for format 2 projects too (it can't tell whether the project was made before them).
Likewise, the changes in 0.2.1 to 0.5.x are listed for format 3 projects.

### Declaring compatible engines (engines)

```json
{ "id": "my_game", "title": "My Game", "format": 4, "engines": { "liminalia": ">=2" }, "entry": "start" }
```

- `engines.liminalia` is the range of engine interface versions the game (and a template someone shares) works with (`>=`, `<`, `^`, `2 - 3` and `||` are understood). It's written the same way, and uses the same version,
  as a plugin's `package.json` and a theme's `theme.json` ("Declaring compatible engines" in [plugins.md](../plugins.md); currently 8). If you don't write it, it isn't checked.
- If it doesn't match, the syntax check warns (`engine-version`). `lim new <folder> --template <template>` also tells you before creating the game when the template's `engines` or `format` doesn't match.
- `format` is the version of how scripts are written, and `engines` is the version of the engine's features (the interfaces for commands and rendering, and the items of themes and project settings).

### Save versions

Save data has a `version` (the version of the save format). When loading, the version is checked, and older versions go through the conversion for each version in turn to reach the current one.
Saves from a newer version than the game, and malformed saves, aren't loaded, and the player is told (the game screen says it can't be loaded, and the current playthrough isn't thrown away).

- Even after updating the engine, saves made with the previous version can be read as they are.
- When rewriting the scenario has moved the place to resume from, it resumes from a nearby line (`save-relocated`). A save inside `@call` or a macro also keeps a marker for where to return (the line after the calling command;
  for a choice with `call=true`, that choice), so even if the caller's lines shift, it returns after the same command. For saves from earlier versions without the marker, if the line just before the return point
  isn't a calling command, it returns after whichever command that calls the called place is closest to the original position.

**After loading**: `afterLoad` (`file#label`) in liminalia.json is the place called right after loading (`@return` goes back to the loaded page).
`temp.` isn't kept in the save, so recalculate anything you need after loading here.

**Game version**: Save data has the version of the game that made it (`version` in liminalia.json; `gameVersion` in the save data), which expressions can read as `save.version`
(read only. For a loaded playthrough it's the version of that save data, for a newly started playthrough the current version, and for save data from before the version was recorded an empty string.
Saving again makes it the current version). When an update changes the name or meaning of a variable, convert save data from earlier versions in `afterLoad`.
Compare versions with `version_before(save.version, "1.1.0")` (they're compared as numbers, so 1.9.0 comes before 1.10.0; an empty version comes before every version):

```
// liminalia.json: "version": "1.1.0", "afterLoad": "common#after_load"
// In 1.1.0, game.affection was renamed to game.love
# after_load
@if version_before(save.version, "1.1.0")
  @set game.love = game.affection
@end
@return
```

As you add conversions, put the `@if` blocks in order from the oldest (a 1.0.x save goes through the 1.1.0 conversion and then the 1.2.0 one too).

If there's a local variable (a macro parameter or `@let`) named `save`, that's read instead.

`saves` sets where saves are kept (desktop version) and whether save data is protected (see exporting in the README).

### Locked voice numbers (voice-lock.json)

Locks the numbers of numbered voices (chapter 7) to each line of dialogue. `lim voice-lock` creates and updates it.
Dialogue in packs (`packs/<id>/scenario`) also plays with the numbers in this file, so `lim voice-lock` (and "Lock numbers" in Studio) and the syntax check count pack scripts too
(they read the main scripts with the pack laid over them, give numbers to pack dialogue, and don't move the numbers of pack dialogue to `retired`). The first time,
it also runs the game with packs laid over the main scripts, and dialogue that only pack scripts have gets the number that plays when the pack is installed. Players can install any combination of packs,
so the combinations are all of them: the main scripts alone, with each pack, with each two packs, and so on (laid in the order of `order` and `id` in `pack.json` like the game, the later pack winning; an export includes all of the project's packs, and the desktop version lays the installed packs over the main scripts).
The first time, smaller combinations run first, and a line that already played in an earlier combination doesn't get numbers from later ones (a combination with no lines left to copy isn't run, and a jump to a scenario the combination doesn't have ends the run there).
With more than 8 packs that have scripts there are too many combinations, so only the main scripts alone, with each pack, and with all packs are read, and
`lim voice-lock` (and "Lock numbers" in Studio) reports how many combinations weren't read (lines that play a numbered voice only in those combinations get no number).
The output of `lim voice-lock` writes the place of pack dialogue as `packs/<folder>/scenario/<scenario>:<line>`.

```json
{
  "lines": {
    "start:v26410599": { "speaker": "Yui", "n": 1, "source": "\"...A visitor?\"" }
  },
  "retired": {
    "start:v8d01e2aa": { "speaker": "Yui", "n": 7, "source": "\"A deleted line\"" }
  }
}
```

- The key is made from the file, the speaker and the original text (if the same line appears several times in the same file, which occurrence it is). Adding or moving lines doesn't change it.
  A line with a fixed line ID at the end (`#line:ID`; chapter 2) uses `file:v@ID`, so rewriting the original doesn't detach the number (a line whose original changed gets `"rerecord": true`).
- Numbers are given only to lines where a numbered voice plays. The script is read from the top, following, for each speaker, whether `@voice-auto` is in effect (set, `@voice-auto-off`, resumed) and
  the `@voice` right before. The start of a file combines the states of the places that jump to it (the `entry` file starts with nothing in effect).
  Each branch of `@if` is read and merged, and a macro call reads the contents of the macro. A file that nothing jumps to is assumed to possibly have any speaker with a setting in effect.
  The numbers of lines that don't play are moved to `retired` (if you make them play later, they get their previous numbers back).
- **The first time**: it runs from "New Game" several times with different choices, and copies the numbers that play with the current counting (locking the recorded numbers as they are).
  Lines whose number changed depending on the route, and lines that played the same number as another line, are listed. Lines not reached in these runs get new numbers.
- **When updating**: locked numbers don't change.
  - New lines get numbers per speaker, starting after the largest number so far.
  - A line whose original text was slightly rewritten keeps its previous number (in the same file, with the same speaker, and with original text close enough). The recorded voice no longer matches the original, so
    it's marked `"rerecord": true` and appears in the output of `lim voice-lock` and in the "needs re-recording" column of the recording script. After re-recording, clear the mark with `lim voice-lock --clear-rerecord`.
    A line whose original stayed the same but whose key changed (which occurrence of the same line it is changed, or a line ID was given) carries over without the mark.
  - The numbers of deleted lines are kept in `retired` and aren't given to other lines (if you bring the line back, it gets its previous number back).
- The dev server reads the lock when it starts (reopen it after updating). Export includes it in the game.

What the syntax check reports:

| code | Contents |
|---|---|
| `voice-unlocked` | A line that isn't in the lock (it doesn't play). Only lines where a numbered voice plays |
| `voice-lock-duplicate` | The same number for the same speaker among lines that are played together (the main scripts alone, or with any combination of packs laid over them; all combinations are checked, however many packs there are) (error) |
| `missing-voice` | A voice file that doesn't exist (only for speakers with a single `@voice-auto` pattern) |
| `voice-lock-outdated` | Numbers for lines that aren't in the current scenario |

### Items and investigation (items)

In `items`, write item name → `{ name, image, description }`. `name` is the name shown, `image` is a picture in the image folder (optional), and `description` is a description (optional).

```json
"items": { "old_key": { "name": "Old key", "image": "items/key.png", "description": "It's rusted." } }
```

| How to write it | Meaning |
|---|---|
| `@item-add old_key` | Add one (`count=`; `notify=false` shows no notification) |
| `@item-remove old_key` | Remove (all of them if `count=` is omitted) |
| `item("old_key")` | Read the count in an expression |
| `@item-select temp.used` | Show the items screen, let the player choose one, and put its name in the variable (an empty string if closed). For letting the player choose what to use at a place being investigated |
| `@open-screen items` | Open the items screen |

- The counts are kept in game variables (with names that expressions can't write), so they come back as they were with save, rewind and load.
- "Items" appears in the menu (only when there are `items`). In the quick menu, you can place it with `items` in `ui.menuBar.items`.
- Places to investigate are made with choice click areas (`x` `y` `width` `height`). You can add `cursor=` (a cursor image on hover) and `tip=` (a short description shown on hover).
  To hide places that have been investigated, use `if=`; to make them unpressable, `locked=`.
- The syntax check confirms the shape of `items`, and that the names in `@item-add` `@item-remove` `item("…")` in the scenario are in `items`.

### Places to investigate (investigation)

Investigation scenes, where the player picks places on the background to examine, are written in `data/investigation.json` and shown with `@investigate name`.

```json
{
  "places": {
    "room": {
      "title": "Examining the room",
      "file": "chapter1",
      "done": "#exam_done",
      "views": [
        {
          "id": "yuika", "label": "Yuika's view", "background": "stills/room_yuika.png",
          "spots": [
            { "id": "shelf", "label": "Check the bookshelf", "rect": { "x": 111, "y": 110, "width": 231, "height": 493 }, "target": "#yuika_shelf", "flag": "exam_shelf" },
            { "id": "window", "label": "Check the window", "rect": { "x": 552, "y": 116, "width": 401, "height": 238 }, "target": "#yuika_window", "required": false }
          ]
        }
      ]
    }
  }
}
```

```
@investigate room
# yuika_shelf
Old astronomy books line the bookshelf.
# yuika_window
The window is locked from the inside.
# exam_done
Yuika "Haru, what do you think?"
```

- Pressing a place calls its scene (`target`; `#label` is a label in `file`). The scene returns to the investigation screen at the next label or the end of the file, without writing `@return` or `@jump` (if the scene does a `@jump`, it doesn't return)
- Whether a place has been investigated is recorded by the command (a game variable that expressions can't write; kept in the save), and if `flag` is written, that variable is also set to `true`. Investigated places get a mark
- Once all required places (those without `required` set to `false`) have been investigated, the game goes to `done` (or to the line after `@investigate` if there is none). With `finish` set to `button`, it goes there when "Finish" is pressed (it can't be pressed until the investigation is done)
- With two or more views (`views`), tabs switch between them (`@investigate room view=haru` sets the first view). A place whose `if` (expression) is false isn't shown, and with `once` it isn't shown after it has been investigated. `tip` is a description shown on hover.
  When returning from a scene, the view that was last shown comes back
- On touch devices, the first tap on a place shows its name (`tip` or `label`) and outline, and tapping the same place again or tapping the name investigates it (a mouse or keyboard investigates with one press).
  On touch devices and in portrait games, text and buttons are made larger (text at least 12px on screen, buttons at least 44px), and small places can still be hit with a finger. The codex and map choices do the same
- A view's `face` (a picture in image) is the face shown on the tab that switches views. With `enter` (a scene), that scene is called the first time the player switches to that view with the tab (returning at the next label shows that view's screen),
  and with `enterFlag`, that variable is also set to `true` (the command also records whether the view was entered)
- When a place is investigated a second time, `again` (a scene), if present, is called instead. `temp.first_visit` in the scene is `true` only the first time the place is investigated (you can also branch with `@if temp.first_visit`)
- Ways to finish without investigating enough: with `incomplete` (a scene) of the whole place to investigate (the level above the views) or a view's `end` (a scene, for finishing in that view; used before `incomplete`), "Finish" can be pressed
  even before the investigation is done, and pressing it jumps there (to have the player come back, write `@investigate room` again where it jumps to; the record of what was investigated stays).
  While required places remain, pressing it first asks "There are places you haven't examined yet. Finish anyway?" (the text key is `investigate.unfinished`;
  it doesn't ask if the player has turned confirmations off in Settings, and a game that replaces the confirmation screen gets `kind` `investigate-finish`)
- `opening` is a title shown large, like a title page, the first time the player enters (it disappears as soon as it's pressed; it isn't shown when returning from a scene, when coming back from a save made partway, or with `@investigate room opening=false`)
- `hitScale` (0.1 to 1) shrinks a place's hit area around the center of its rectangle (so the edges of the picture can't be pressed by accident)
- "Show spots" next to the title lights up every place that can be investigated (press it again to turn it off; the wording is `investigate.reveal`). With `progress` set to `true`, the number of required places investigated (`1 / 3`) appears next to the title
- With `hud` set to `true`, the HUD text (`@hud-text`) stays visible on top while the investigation screen is shown (HUD buttons aren't shown, and it's hidden while the menu or another screen is open). The same goes for map choices
- A view's background stays as the background after the investigation screen is closed, and if it's an image in extra.cg, it's unlocked as a CG (it also counts in the check for CGs that never appear)
- When running without a screen (the all-routes test, route exploration), uninvestigated required places are investigated in order. Studio's flowchart draws arrows to the places' scenes and to `done`
- `@investigate-reset room` erases the record of what was investigated and of the views entered (so the player investigates from the start again)
- While the investigation screen is shown, the player can still open the menu, save, load, the backlog and the settings (Esc, right-click, the shortcut keys and the menu button on phones).
  Closing them returns to the investigation screen, and a save made while it's shown comes back to the same view when loaded. The same goes for map choices, the codex, `@item-select`, `@text-input` and `@dialog`
- The syntax check confirms the shape, jump targets, that backgrounds exist, expressions, flags ([data shapes](../plugins.md#作品のデータの形data)), and that the names and views in the scenario are in the data. In Studio, you can edit it in "Investigation" under "Data" in "Plugins," dragging rectangles on top of the background

### Choosing a destination on a map (map-choice)

Scenes where the player chooses where to go by pressing a point on a map are written in `maps` in the same `data/investigation.json` and shown with `@map-choice name`. Pressing a point shows its name, picture and description in the description panel,
and "Choose this" chooses it (with `confirm` set to `false`, the point pressed is chosen right away).

```json
{
  "maps": {
    "town": {
      "title": "Destination", "prompt": "Where to?", "file": "chapter3", "background": "maps/town.png",
      "spots": [
        { "id": "station", "label": "Station", "rect": { "x": 220, "y": 300, "width": 140, "height": 60 }, "target": "#station", "desc": "The busy square in front of the station.", "image": "maps/station.png" },
        { "id": "park", "label": "Park", "rect": { "x": 640, "y": 280, "width": 140, "height": 60 }, "target": "#park", "locked": "!game.has_key" }
      ]
    }
  }
}
```

```
@map-choice town result=temp.where
```

- The `id` of the chosen point goes into the `result` variable, and the game jumps to the point's `target` (`#label` is a label in `file`). A point without `target` goes on to the line after `@map-choice` (branch with the `result` variable)
- A point whose `if` (expression) is false isn't shown, and one whose `locked` (expression) is true is shown but can't be chosen. `panel` (`right`, `left`, `bottom`) sets where the description panel goes. The panel sits on top of the map, so a point under it can't be pressed (the syntax check reports it as `map-spot-hidden`). In portrait games the panel goes at the bottom across the full width regardless of `panel` (at most 40% high), and the syntax check looks at that area
- When a locked point is selected, the description panel shows `lockedDesc` (such as "Needs the gate key"; `lockedDescEn` in English) under the description
- The map picture (`background`) is looked up in `bgimage`, then in `image` (the same rule as the codex map, so the same path shows the same picture). A point's `image` comes from `image`
- While the map is shown, the menu, save, load, the backlog and the settings can still be opened (closing them returns to the map). A save made while the map is shown comes back to the same map when loaded. When running without a screen, the first point that can be chosen is chosen (the all-routes test tries every point).
  Studio's flowchart draws arrows to the points' `target`s. In Studio, you can edit it in "Choose on a map" in "Investigation" under "Data," dragging rectangles on top of the map

### Codex (codex)

Records such as descriptions of people, incidents, terms and items are written in `data/codex.json`. "Records" (changeable with `title`) appears in the menu (and the extras), and `@codex` or `@open-screen codex` also opens it.

```json
{
  "title": "Notebook",
  "categories": [{ "id": "people", "label": "People" }, { "id": "terms", "label": "Terms", "sort": "reading" }],
  "entries": [
    {
      "id": "yuika", "category": "people", "title": "Yuika", "reading": "yuika", "image": "codex/faces/yuika.png",
      "if": "game.met_yuika",
      "sections": [
        { "text": "Visits the observatory at the top of the hill." },
        { "id": "past", "title": "Three years ago", "text": "She started watching the stars one summer three years ago.", "if": "game.yuika_past" },
        { "id": "secret", "text": "…", "locked": true }
      ],
      "related": ["haru"]
    }
  ]
}
```

| How to write it | Meaning |
|---|---|
| `if` of an entry (expression) | Unlocks when it becomes true. `@codex-unlock yuika` also unlocks it |
| `item` of an entry | Unlocked while the player has the item (a name from items) (for item descriptions) |
| `if` of a section (`sections`) | Unlocks an entry's text section by section, a little at a time (gradual reveal). Sections without a condition unlock with the entry, and `locked` sections are unlocked with `@codex-unlock yuika section=secret` |
| `sort` of a category | `reading` sorts by reading (for a glossary); otherwise, the order written |
| `type` of a category | How it's shown. `list` (a list; the default), `timeline` (a timeline, with each entry's `date` as a heading, in the order of `order`), `relations` (a relationship chart, placing entries at their `x` `y` and drawing the lines in `links`), `map` (a map, placing marks at `x` `y` on the category's `map` picture. Like map choices, the picture is looked up in `bgimage`, then in `image`, where it used to go) |
| `x` `y` of an entry | The position in a relationship chart or map (a percentage from the top left of the chart, 0 to 100; if not written in a relationship chart, entries are arranged in a circle). In Studio's data form, you can place it by clicking on the category's map picture |
| `links` of an entry | Lines in a relationship chart (`to` is the entry at the other end, `label` the relationship, `tone` `positive` (on good terms), `negative` (in conflict; dashed) or `neutral`, and `if` the condition to show it). Shown when the entries at both ends are unlocked. Lines both ways between the same two (A to B and B to A) are bent into arcs instead of overlapping, so both relationships show |
| `notify` | `false` shows no notification when it unlocks |

- Unlocked entries and sections are kept in this playthrough's record (kept in the save) and in the record shared by all saves (`system.codex_unlocked`). The codex opened from the extras shows the record shared by all saves
- The conditions are checked when a variable they read changes (`@set`, a command's result, choices made and the number of scenes entered, items, and a plugin's `setVariable` and `variablesChanged`),
  and newly unlocked things are announced at the edge of the screen (not for things unlocked from the start, or while skipping). Checks happen only when a variable a condition reads (`game.x` and so on) changes.
  The announcements are the same stacking notices as `@notify` (`.lm-notice`): things unlocked one after another are listed one by one, and two or more unlocked at once are summed up by count ("Recorded: 3 entries").
  If a condition reads something that changes from page to page, such as `read()` or `lang()`, or reads local variables, it's also checked every time a page is shown. A "New" mark stays until it's read
- When the codex is opened without naming an entry (from the menu, or `@codex`) and when the category changes, the category's entry with a "New" mark, or else the first one in the list, is shown on the right.
  Being shown this way doesn't count as read, and the "New" mark stays (an entry counts as read when the player picks it, or when it's opened with `@codex name`)
- The syntax check confirms the shape, assets, expressions, the entries in `related` and `links`, and that the names and sections in `@codex` and `@codex-unlock` are in the data, and warns about flags that a condition reads but no scenario sets
- A project can replace the codex screen (`screens.codex` of `WebPlugin`; [writing plugins](../plugins.md)). The standard commands decide which entries, sections and lines are unlocked and which have the New mark, and pass them on

### Extras (extra)

When you write lists in `extra` in `liminalia.json`, "Extras" appears on the title screen of the default system screens (once at least one thing has been unlocked).
From a scenario, open it with `@open-screen extra`.

```json
"extra": {
  "cg": [{ "id": "ending_a", "title": "Dawn", "images": ["stills/ending_a.png", "stills/ending_a2.png"] }],
  "replay": [{ "id": "ending_a", "title": "The hill at dawn", "target": "ending#a", "thumb": "stills/ending_a.png", "variables": { "game.route": "a" } }],
  "music": [{ "file": "quiet_night.ogg", "title": "A quiet night" }],
  "achievements": [{ "id": "first_star", "title": "First shooting star", "description": "Found a shooting star", "hidden": false }]
}
```

| Kind | How it's unlocked | Contents |
|---|---|---|
| `cg` | `@cg-unlock`, or showing it with `@bg` (plugin commands too, when shown with a parameter set to unlock CGs) | `images` are paths from `assets/bgimage/`. Only unlocked images can be viewed, and a click moves to the next variation. `thumb` is the image in the list (the first unlocked image if omitted). With two or more `group`s (headings) or `chapter`s (an id in `chapters`; the chapter's number or title becomes the heading), the list is split into tabs. `description` is shown with the title on the screen for viewing an image large (the controls are under extras in docs/player.md) |
| `replay` | `@replay-unlock id` | Plays from `target`, and returns to the replay screen in the extras at `@replay-end` or the end. Saving and loading aren't available during a replay. `@replay-end` does nothing outside a replay, so it can be placed in the flow of the main story. `variables` (`{ "game.route": "a" }`; `game.` and `temp.`) are variables set before the replay starts, to pass values decided in the main story to the replay. The expression `replaying()` tells you whether you're in a replay |
| `music` | Played once with `@bgm` | |
| `achievements` | `@achieve id`. For an achievement with a `goal`, `@achieve-progress id` (`add=` adds, default 1; `set=` sets the count) advances the count, and it unlocks when it reaches `goal`. An achievement with `endings` unlocks when the number of endings of that kind seen reaches `goal` | Only the first unlock is announced. `hidden` hides the name and description until it's unlocked. `icon` is a path from `assets/image/`. Writing `goal` (an integer of 1 or more) makes it a counting achievement, and the list shows "current count / goal". With a kind of ending in `endings` (`"*"` for any kind), each time a command that ends the playthrough runs, the count becomes the number of endings of that kind seen (counted the same way as `endings()` in expressions; the same ending counts once). No `@achieve-progress` is needed; write `goal` too. The desktop version also sends it to Steam achievements, and the mobile version to Game Center and Google Play Games achievements (docs/distribution.md) |
| `movies` | Played once with `@movie` | `{ file, title, thumb, subtitles }`. `file` and `subtitles` are from `assets/video/`, `thumb` from `assets/image/`. Pressing one plays it full screen with a control bar |
| `characters` | Showing the sprite | A list of `{ who (character ID), name }`. Only the variants that have been shown can be viewed large, by sprite set (layered sprites are the stacked picture; `@chara smile+blush` counts as seeing `smile`) |
| `endings` | Reaching an ending scene (a scene with `@title-screen ending=`) | `true` shows a tab with the list of endings. It lists the endings of the flowchart built from the scenario, and shows the name (the kind's wording and the name in `title=`) and scene title only for those reached (they're counted even without writing `extra.flowchart`). Each row has the kind in `data-kind` |

- The unlock records are in system variables (shared by all saves): `cg_unlocked` `replay_unlocked` `bgm_heard` `achievements` `movies_seen` `sprites_seen`. The counts of counting achievements are in `achievement_progress` (in an expression, `system.achievement_progress.read_all`).
  Count the endings seen with `endings()` (all of them) and `endings("bad")` (that kind) in expressions (the same ending counts once however often it's seen; the current playthrough's ending counts once the command that ends the play runs).
- Under the heading of the extras screen, the completion rate is shown (the overall rate, and the counts of read text, CGs, replays, endings and achievements). The overall rate is the average of the shares of the items that have a total (read text, endings, CG images, replays, music, movies, achievements).
  Read text and endings are counted with the flowchart built from the scenario (they're counted even without writing `extra.flowchart`).
  Plugins and project screens read it with `system.completion()` (`SystemController`; `{ read, endings, cg, replay, music, movies, achievements, rate }`, where each item is `{ done, total }`).
- Unlocking when a CG is shown is done by the runtime (the same while skipping, during a replay, and in runs without a screen, such as working out the current position in Studio or the all-routes test).
  What's unlocked are images in `images` of `cg` or in the `cgAuto` folders, shown with a parameter set to unlock CGs (images in `@bg` and `@bg-place`; in plugins, `t.asset("bgimage", "Title page", { cg: true })`).
- The syntax check confirms the shape of the lists and where replays start, and warns if an unlock command in a scenario names something not in the lists (for `@achieve-progress`, it also warns about achievements without a `goal`).
  Images in `cg` that no scenario shows and no `@cg-unlock` unlocks are warned about (because they can't be seen in the extras; if the scenario has a command that names a CG image with an expression, it's info instead of a warning).
  A `@cg-unlock` in the same run of command lines (with no text in between) as a command that shows the same image as a CG isn't needed, so it's reported as info (these can be deleted all at once from the check in Studio).
  `{@cg-unlock …}` inside text is also checked (if the image is shown by `{@bg …}` on the same line or by the commands right before the line, it's info; since the line can't be deleted as a whole, it isn't included in Delete all).
  Unlock commands inside text (`{@cg-unlock}` `{@achieve}` and so on) are also warned about if they name something not in the lists.

### Chapters (chapters)

In `chapters` in `liminalia.json`, write each chapter's number, title, subtitle (such as a title in another language) and its scenario files in one place.

```json
"chapters": [
  { "id": "prologue", "number": "Prologue", "title": "Beginnings", "files": ["prologue_*"] },
  { "id": "ch1", "number": "Chapter 1", "title": "The hill where we wait for stars", "subtitle": "THE HILL OF STARS", "files": ["chapter1_*"], "cover": "covers/ch1.png" }
]
```

| Item | Contents |
|---|---|
| `id` | Name (required). The value returned by the expression `chapter()` |
| `title` | Title (required) |
| `number` | How the number is written (`Chapter 1`, `EPISODE 01` and so on) |
| `subtitle` | A subtitle or a title in another language |
| `files` | The chapter's scenario files (without the extension; `*` matches any run of characters). A file that matches two chapters belongs to the one written first |
| Others | Items your project adds (a picture to show on the chapter's title page and so on). Read by plugin commands |

Where it's read:

- The expression `chapter()`: the `id` of the chapter of the current scenario file (empty if it isn't in any chapter).
- The standard chapter card and chapter end (`@chapter-card`, `@chapter-end`): an omitted number, title or subtitle comes from the current chapter. The look is set with `ui.chapter` in `liminalia.json` (backdrop, picture, font, text color, text size and the rule; [player.md](../player.md)),
  and otherwise follows the theme's colors and font (`titleBg`, `fg`, `accent` in `ui.system` and the text font). The project's CSS can restyle `.lim-chapter` (`--card`, `--end`).
  When shown, the number and title are passed to screen readers and text-to-speech. The end mark of `@chapter-end` is 完 if omitted (End when playing in English).
  With `leave=mask` (the default for `@chapter-end`), the script continues with the screen covered in black, and the next `@mask-off` opens it (`@staff-roll` takes the same parameter).
  The covered state is kept in saves and stays covered after load, rewind and skipping.
- Plugin commands (a project's own chapter title page or chapter end): `ctx.runtime.chapter` is the current chapter (`{ id, title, number, subtitle, … }`; `null` if none).
  If the command fills in omitted parameters from the chapter information, you don't have to write the same values for every chapter.
- Save slot headings: the default save screen shows the number and title of the chapter of the file where the save was made (`ui.chapterNames`, if written, takes priority). Project screens can look up the same chapter with `chapterOf(chapters, position.unit)` from `@liminalia/lang` (the project information in the player is `project.chapters`).
- CGs in the extras: writing `"chapter": "ch1"` in `extra.cg` lines them up under that chapter's heading (`number`, or `title` if there is none) without writing `group`.
- Chapter select (`extra.chapters`): with the same `id` as in `chapters`, `title` can be omitted (the chapter's title is used).

The syntax check reports malformed entries, duplicate `id`s and chapters without a title (`bad-chapters`), `files` that match no scenario file and files in two chapters (warning `chapter-files`),
and a `chapter` in `extra.cg` that isn't in `chapters` (`bad-extra`).
A `@chapter-card` or `@chapter-end` with no number, title or subtitle in a script file that isn't in any chapter gets a warning (`chapter-card-empty`; a blank card appears.
One inside a macro is checked against the chapter of the script file that defines the macro). In a project that uses chapters, a script file reached from the start that has text but isn't in any chapter
is reported as info (`not-in-chapter`; while it plays, the chapter heading in save slots and `chapter()` are empty. Reaching is followed from the start positions such as `entry` through `@jump`, `@call`, options,
target-type parameters and targets inside called macros. For a script file you keep out of the chapters, write `// lim-ignore-file not-in-chapter` at its top).

### Languages (languages)

List the languages the game can be played in under `languages` in `liminalia.json` (the first one is the language of the original). The original scenarios stay as they are, and translations into other languages go in `lang/<language>.json`.
In the examples below, the original is Japanese and the translation is English.

```json
"languages": ["ja", "en"]
```

You can also write only the source language (`"languages": ["en"]` for a project written in English). The system screens then appear in that language. A project without `languages` is treated as a Japanese project.
Projects made with `lim new --lang en` and with the Studio app shown in English get `"languages": ["en"]`.

```json
{
  "language": "en",
  "speakers": { "アカリ": "Akari" },
  "lines": {
    "start:l3f2a91c0": { "source": "「着いた……っ」", "text": "“Made it…!”", "speaker": "アカリ" },
    "start:c0a1b2c3d": { "source": "扉を調べる", "text": "Check the door", "speaker": "choice" }
  },
  "ui": { "title.start": "Begin" }
}
```

**What gets translated**: text lines (dialogue and narration), choice text, speaker names, the wording of the system screens, and the following.

| Kind | Contents | Key |
|---|---|---|
| Command text | Text written literally in parameters marked for translation in command lines (the text of `@layer-text` `@motion-text`, the text of `@chat`, the title of `@chat-open`, the message and buttons of `@dialog`, the heading of `@text-input`, the heading of `@item-select`, the text of `@backlog-add` `@window-title` `@presence`, `caption` of `@se`, `title` of `@title-screen` (and wording in `ending` from script format 2 or earlier), `tip` of choices, and `t.text` parameters of plugin commands), and the text in `@set variable = "text"` | `file:a…`. `note` holds the command name (for `@set`, the variable's name too, as in `@set game.name`) |
| Project settings text | In `liminalia.json`: `title` (the project's title, shown on the title screen and as the page title); the titles, numbers and subtitles in `chapters`; titles and descriptions in `extra` (CGs, replays, music, achievements, glossary terms with their readings, aliases and descriptions, chapter select, movies, names in the character gallery, `cgAuto.groups`, `flowchart.titles`); names and descriptions in `items`; and in `ui`, `chapterNames`, `contentWarning`, `contentFilter.label`, `help.pages`, `captions.sounds`; the wording in `endingKinds` | `liminalia.json:t…`. `note` holds the location (`extra.cg` and so on) |
| Project data text | Text in `data/*.json` that the data shape marks for translation (the codex's headings, names, descriptions, body text, timeline dates and relations; the titles, prompts, names, descriptions, locked reasons and opening titles of investigation places and maps. For plugin data, `translate` on `d.string` and `d.text`) | `data/<file>:t…`. `note` holds the file and the location (`data/codex.json /entries/0/title`) |

- Project data text uses the English fields (`titleEn`, `labelEn` and so on) first in English, and text with an English field isn't listed in the English translation file. Other languages use the translation file, showing the source text when there's no translation.
  After switching languages, the change shows the next time the screen opens
- `@set` is translated when the right side of `=` is only literal text (`@set game.name = "Yuika"`). Values without letters (kana, kanji, Latin letters and so on) (`"42"`), text built with an expression (`"Chapter " + n`) and text added with `+=` aren't translated.
  If there's a translation, the variable gets the translation (changing the language afterward doesn't change the value already in the variable). Leave the translation empty for text used for comparison in conditional branches (such as `@set route = "akane"`).
- Parameters that hold the name of a speaker or the other party (the speaker and `me` of `@chat`, and `t.name` of plugin commands) are listed in `speakers`.
- Values written as expressions (`(…)`) and the text of inline commands (`{@…}`) aren't collected (inline ones are translated inside the translation of the line). Even for an expression value, it's replaced if the same file has a translation of command text with the same original.
- Command text and project settings text aren't read with text syntax (ruby and so on) and are used as written.
- Text that stays on screen (the text of `@layer-text` and `@motion-text stay=true`, the balloons of `@chat` and the title of `@chat-open`, the balloons and names of regular dialogue, the balloon of the chosen choice)
  is kept in the save with its translation key. Changing the language while playing shows it again in the current language right away, and loading something saved in another language also shows it in the current language
  (text written as an expression stays as it was when shown; an expression `{= …}` inside a balloon uses its value when shown again). The text of the page being read and NVL paragraphs change from the next page.
  Finished NVL paragraphs and text kept with `{noclick}` are also kept in the save with their line keys, and loading something saved in another language shows them in the current language
  (paragraphs in save data made with an earlier version stay in the language they were saved in).
  Chapter information (`ctx.runtime.chapter`) changes from the next playthrough started.

**How to write `text`**

- The same syntax as text in .lim (ruby, `{br}`, `{click}`, inline commands).
- If the original has inline commands such as `{@voice …}`, write them in the translation too (the syntax check warns about missing ones).
- A line with an empty translation shows the original.

**Keys and updating**

The keys of `lines` are made from the file name, the kind and the original text (`lim i18n` makes them, so don't write them by hand). Rewriting the original changes the key, and the old translation is no longer used as is.
`lim i18n en` (and the translation screen in Studio) keeps existing translations and adds new lines with empty translations. Translations that are no longer used aren't thrown away, and are handled as follows.

| Case | What happens |
|---|---|
| A line with the same original exists under another key (the file was renamed, or the line was moved to another file) | The translation carries over as is |
| The same file has a translation of a close original (the original was slightly rewritten) | The translation stays empty, and `previous` holds the old original and translation. The translation screen in Studio shows it as "Earlier translation," and clicking "Use" puts it into the translation field |
| Neither | Kept in `stale` (if you change the original back, it returns to that line; delete it if you don't need it) |

Only lines that are no longer used and have an empty translation are removed. When you rename a scenario in Studio, the translation keys are rewritten too.

The game uses, for every scenario, the translation of the last installed pack (in pack order) that has one for that language (`packs/<id>/lang/<language>.json`), or the main one if none does.
So `lim i18n` (and the translation screen in Studio) and the syntax check count translations used only by pack scripts as used: they aren't moved to `stale` or reported as `unused-translation`.
Lines of a pack with no translation for that language show with the main translation, so `lim i18n` lists them in the main translation and the syntax check counts them as untranslated. A pack's translation is checked
against the main scripts with that pack laid over them (a script with the same name is the pack's), and the lines of packs that show with it when installed together (packs without that language, and earlier packs with it) count as untranslated too.
Scripts of earlier packs that the pack replaces with a script of the same name never show with its translation, so they aren't counted (only lines that show in some combination of packs count).

**Lines with a fixed line ID**: a line with `#line:ID` at the end (chapter 2) uses the key `file:l@ID` (`file:c@ID` for choices), which doesn't depend on the original.

```json
"start:l@3f2a91c0": { "source": "「おはよう、今日は早いのね！」", "text": "“Morning. You're early.”", "translatedFrom": "「おはよう、今日は早いのね」", "speaker": "アカリ" }
```

- Rewriting the original doesn't change the key, and the translation keeps being used. `lim i18n` keeps the original at the time of translation in `translatedFrom` (it's removed if you change the original back).
  The syntax check reports their number with `outdated-translation`, and `lim i18n <language> --export xliff --changed` exports only the ones to translate again. Translating them again and importing removes `translatedFrom`.
- When a line is moved to another file, the translation carries over too if the ID is the same and the original is close.
- `lim i18n --stamp-ids` gives IDs to dialogue, narration and choices without one, and moves the keys in the translation files of every language to ID keys
  (when two or more lines with the same original shared one translation, they're split into per-line keys, and if there were per-scene translations, the translation for that line's scene is copied).
  The keys of the locked voice numbers (`voice-lock.json`) are moved too, and the numbers are used as they are. With a language, the translation file for that language is updated right after.

**Translating by scene**

The same original in the same file (short lines such as 「はい」, "yes," or 「……」) uses one translation. To translate it differently by scene, write `contexts`.
For items whose original appears in two or more scenes (labels), `lim i18n` lists the names of those scenes with empty translations. How the key is made doesn't change.

```json
"start:l3f2a91c0": { "source": "「はい」", "text": "“Yes.”", "speaker": "アカリ", "contexts": { "shop": "“Sure.”", "rooftop": "" } }
```

- The scene is the nearest label before that line. Lines before the first label and lines inside `@define` have no scene and use `text`.
- If a scene's translation is empty, `text` is used. It works for text lines, choice text and command text.
- In tables and XLIFF, they follow right after the item, in rows of `key#scene` (they aren't counted in estimates of the amount to translate).
- When you rename a label in Studio, the scene names of that file's items change too. Even if a scene disappears from the scenario, the ones with translations written are kept.

**System screen wording**: Japanese and English are built in. Other languages are based on English and overridden with `ui` keys (`title.start`, `menu.save` and so on; the paths in the table in strings.ts of the default system screens).
The screens of the standard commands (codex, investigation, map choice, chapter end) take their wording from the same table (`codex.title`, `investigate.finish`, `mapChoice.go`, `chapter.end` and so on). The keys for each screen are in the table in [screens.md](../screens.md).

- For languages other than Japanese and English, `lim i18n` (and the translation screen in Studio) lists every key that can be overridden, with the English original (`"title.start": { "source": "New Game", "text": "" }`).
  Keys with an empty translation show English. You can also write only the translation as a string (`"title.start": "Nouvelle partie"`; the next `lim i18n` turns it into the form with the original).
- Keys whose English changed when the engine was updated keep using the translation, and the English at the time of translation is kept in `translatedFrom` (they can be exported with `--changed`).
- In tables and XLIFF they're listed in rows of `ui:key`, with English as the original. Keys not in the English table (ones the project added and so on) are left as written.

**Handing off translations (tables and XLIFF)**

`lim i18n <language> --export csv|xliff --out file` exports, and `--import file` imports the file with the translations filled in ("Export" and "Import" on the translation screen in Studio do the same).

- The columns of the table are `key` `kind` (line, choice, command, setting, speaker, ui) `speaker` `source` `translation` `previous_source` `previous_translation` `context`.
  The `context` column and `note` in XLIFF hold the scene, the position (file and line), the text lines before and after, and a length guide (the number of characters shown in the original; for system screen wording, the number of characters in English).
  `--lang en` writes these in English.
- In XLIFF, the syntax of text lines and choices becomes inline elements that translation tools don't break: `{br}` `{click}` `{noclick}` become `<x/>`,
  `{r …}` `{= …}` `{@…}` `{img …}` become `<ph>` with their contents, and syntax that encloses text (`{b …}` `{c …}` `{size …}` and so on) becomes `<g>`. They're turned back into .lim syntax on import.
  Enclosures that exist only in the translation are exported with `<bpt>` and `<ept>`.
- `--untranslated` exports only items without a translation, and `--changed` only items whose original changed after translation (those with `previous` and those with `translatedFrom`). With both, items that match either.
- On import, items are looked up by key, and the following aren't written. `lim i18n` shows the reason and the position (the row in the table, the line in the XLIFF, the character in the translation).
  - Lines whose original differs from the current scenario (the script changed after exporting). The keys are listed.
  - For text lines and choices, translations that can't be read as .lim text (an unclosed `{` and so on), and `<g>` or `<x/>` not in the original.
  - Translations missing an inline command from the original (`{@voice …}` and so on) are written, and reported.

**The language being played**

- Chosen with "Language" in the Settings screen (and remembered). If none has been chosen, the one matching the browser's language, or the language of the original.
- When changed while playing, the system screens change right away and the text from the next page.

**Fonts and text sizes by language**

In `ui.languages`, write the look to layer on for each language ("Text per language" in Studio's Game settings). The one for the language being played is layered onto `ui`,
replacing only what's written for each item (if you write only `text.size`, the other text settings stay as they are). `fonts` are added. You can write one for the original language too.

```json
"ui": {
  "text": { "font": "\"Hiragino Mincho ProN\", serif", "size": 26 },
  "languages": {
    "en": { "fonts": [{ "family": "Latin", "file": "fonts/latin.woff2" }], "text": { "font": "Latin, serif", "size": 22, "lineHeight": 1.5 }, "choice": { "size": 20 } }
  }
}
```

- You can write `fonts`, `text`, `message`, `name`, `glyph`, `choice`, `chat`, `system` and `ending` (each with the same shape as the same item in `ui`). Other items are a syntax check error.
- Changing the language while playing changes them right away. Font files are included in the check that assets exist.

**Assets by language**

- Put images with text in them, voices, video subtitles and so on under `assets/<kind>/@<language>/`, at the same path as the original
  (`assets/bgimage/@en/title.png` is `assets/bgimage/title.png` when playing in English). If there isn't one, the original asset is used.
- When the language changes while playing, they change from the next thing shown. The asset list in Studio shows how the original asset is used.

The state (variables, read status, saves) is shared regardless of language. Per-speaker handling (voice volume, lip sync) looks at the speaker name of the original.
Display names (`{name …}` and `@name` in chapter 2) written as plain text are listed in `speakers` and translated like speaker names.

## 11. An example of importing from TyranoScript

The original .ks (the character is defined in another file as `[chara_new name="Yuika" jname="Yui" …]`):

```
[chara_show  name="Yuika"  face="smile"  ]
[tb_start_text mode=1 ]
# Yuika
"Morning. You're up early today."[p]
#
Outside the window, the rain was letting up.[p]
[_tb_end_text]
```

.lim:

```
@chara Yuika smile at=auto time=1s wait=true if-hidden=true
Yui "Morning. You're up early today."
Outside the window, the rain was letting up.
```

- `tb_start_text` / `_tb_end_text` / `[p]` / lines that only switch the speaker disappear.
- Parameters equal to the .lim defaults aren't written. On the other hand, TyranoScript's defaults (automatic placement for `[chara_show]`, `time=1000`, `wait=true`,
  and doing nothing when already on screen) differ from the .lim defaults, so they're written out.
- The speaker becomes the text shown in the name box (`jname` of `[chara_new]`).
- tatie's `[tatie name="Yuika" variant="smile" position="left" mode="show"]` becomes `@chara Yuika smile at=left time=500ms if-hidden=true`.

How each tag is handled is in [tyrano-import.md](../tyrano-import.md).

## 12. `lim` commands

Locations are written the same way for all commands: `file` or `file#label`.
`lim help` and `lim command --help` show usage, and `lim version` (`--version`) shows the version (they work outside a project too).
Unknown commands and options stop with a similar name suggested (exit code 2).

Every command chooses the language of its usage, errors and progress messages the same way: `--lang en` (or `--lang ja`) if given, otherwise the
`LIMINALIA_LANG` environment variable (`en` or `ja`), then the terminal's language (the first of `LC_ALL`, `LC_MESSAGES` and `LANG`: Japanese if it starts with `ja`,
undecided for `C` and `POSIX`, English for anything else), and Japanese if none of these decides. Without `--lang`, `lim new` makes the project in this language
(the English sample or blank project in English). The `--lang` of `lim shot` is also the language to play in, and a language other than `en` and `ja` doesn't
choose the output language. The keys and values in `--json` output don't change with the language.

| Command | What it does |
|---|---|
| `lim new <folder>` | Creates a new project from the template (`templates/default`) (`--title` / `--id`) |
| `lim check` | Syntax check (chapter 9). Checks syntax, types, undefined speakers, labels, characters, and jump targets in other files. With suggested fixes (`--json`). Diagnostics are sorted by file, line and column. `--fix code,…` applies the suggested fixes for those codes across all files before checking (`--fix chara-solo` turns the one-at-a-time style into `solo=true`) |
| `lim explain [code]` | Shows the severity, contents, an example with its fixed form, and the section of the docs for a diagnostic code (from the tables in chapter 9; the list if omitted; `--lang en` for English; works outside a project too) |
| `lim test [file or folder…]` | Runs the automated script tests (`tests/*.limtest`) ("Script tests" below). The exit code is 1 if something differs from what's expected. `--github` for annotations, `--json`, `--lang en` |
| `lim reach <location>` | Searches for a way of choosing that reaches that location (`file#label`, `file:line`, `file`) from the start (`entry`), and shows the choices to make, the condition variables at the time it's reached, and how to write it as a test. If it can't be reached, shows the conditions for entering and the lines that set the condition's variables (`--timeout seconds`; default 30; `--json`). The search is the same as Studio's search for unreachable lines. `--ending kind or title` searches for a way to reach an ending (found the same way as `expect ending`) and writes the test with `expect ending`, and `--endings` lists whether each ending is reached |
| `lim trace <location> [--choose 1,north]` | Runs without a browser and prints pages, speakers, commands and choices. `--set game.x=expression` sets a value before starting (can be written any number of times; `system.` `temp.` too), and `--from-state file.json` continues from a save (the `save` of `--json` output, or save data itself). Commands are shown in .lim syntax (unnamed parameters, duration units), listing only the values changed by the parameters you wrote and the project defaults (`commandDefaults`) (`--json` gives all values). `--choose` takes numbers (from 0) or choice text (the same text, or a choice containing it). The exit code is 1 if there's a runtime error. A loop that keeps coming back to the same choice with no text in between is stopped and reported once every way of choosing has been tried (`choice-loop`). The last line, "End: reason (file:line)", shows the last line that ran (the `@title-screen` line if it ended there; `endedAt` in `--json`) |
| `lim coverage` | Runs every file, widening to choices it hasn't tried yet, and reports text coverage and runtime diagnostics (`--runs N` is the per-file limit, 8 by default; it stops early once every way of choosing has been tried; `--seeds N` runs with different random seeds; `--min-lines`, `--require-endings`, `--json` and `--github` for CI thresholds are in [ci.md](../ci.md)) |
| `lim fmt` | Tidies command lines and expressions (below). `--check` doesn't rewrite anything and fails if any file isn't tidy (it shows each place to fix as `file:line` with the line before and after, up to 10 places per file). `--indent 2` (`tab`, `keep`) sets the block indentation |
| `lim migrate` | Moves the scripts to the current format (earlier command names to the current names, and `format` in liminalia.json to the current version; "Script format versions" in chapter 10). `--check` doesn't rewrite anything and fails if there's anything to move. `--keep-behavior [name,…]` also writes settings that keep the old behavior where defaults changed |
| `lim script-export` | Exports the script for proofreading (see "Proofreading" below). `--format text` (default) or `html`, `--out` for where to write (default `exports/script`), `--lines` for line numbers at the start of text lines |
| `lim prose extract` / `lim prose apply` | Extracts only the text with a key for each line (`--out`, `--ruby aozora\|lim`, `--lang en` for an English note at the top), and writes edited text back after confirming that nothing but the text changed (`--check` only checks; see "Proofreading" below) |
| `lim voice-lock` | Locks the numbers of numbered voices to each line of dialogue (chapter 10) |
| `lim rename <kind> <old name> <new name>` | Renames something and rewrites the places that refer to it too (the same rewriting as renaming in Studio; the earlier version of the script stays in the change history). The kinds are `label` (`file#label` to the new label name), `file` (a scenario name), `variable` (`game.x`), `character` (a character ID), `speaker` (a speaker name), `asset` (`kind/path`) and `macro` (a `@define` name). Script tests (`tests/*.limtest`), `files` in `chapters` and the keys of `scenes` in liminalia.json are rewritten too. For assets, commands inside text (`{@se …}`), `{img …}`, translations and `url()` in the project's CSS are rewritten as well. References that couldn't be rewritten (jump targets decided by expressions, chapter wildcards that won't match the new name, asset names left as text in data or templates and so on) are listed. If a script file can't be read as UTF-8, nothing is rewritten. `--lang en` for English |
| `lim shot <location>` / `lim shot --title` | Takes a screenshot of the given page or the title screen (`--video` records from there, advancing at real speed; [ci.md](../ci.md)) |
| `lim dev` | The player's dev server |
| `lim profile [<location>]` | Opens the player and advances a set number of pages while measuring the frame rate, memory, asset loading and the number of DOM elements ([player.md](../player.md)) |
| `lim studio` | Studio (runs on the same dev server as `lim dev`; [studio.md](../studio.md)) |
| `lim import` | Imports from TyranoScript .ks. Compares the text to confirm it matches, and lists the parts that can't be converted, with reasons. Macros are gathered into `@define` in one file ([tyrano-import.md](../tyrano-import.md)) |
| `lim import-ink` / `lim import-yarn` / `lim import-renpy` / `lim import-twine` | Converts and imports Ink, Yarn Spinner, Ren'Py and Twine (Twee 3) scenarios. Syntax it can't handle becomes comments and is listed in the report ([ink-yarn-import.md](../ink-yarn-import.md)) |
| `lim backport --base <base>` | Writes changes made to the .lim of an imported project back into the .ks, then imports again to confirm ([tyrano-backport.md](../tyrano-backport.md)) |
| `lim build <browser\|mac\|windows\|linux\|android\|ios\|all>` | Exports. Checks before exporting, and starts the result after exporting to confirm it (for the mobile versions, see exporting in the README; `ios --device` installs and starts it on a device) |
| `lim reference` | Generates the command reference from the definitions of the built-in commands and the plugin commands (`--json` for machine-readable output) |
| `lim patch --base <previous export>` | Makes a patch (pack) with only what changed, from the difference with the previous export (patches in [distribution.md](../distribution.md)) |
| `lim psd <file> <character>` | Imports the layers of a PSD or PSB as a layered sprite (top-level groups are layers, the layers inside them are the pictures to choose from, and visible ones are the defaults; `--appearance` sets the sprite set and `--folder` the folder in fgimage for the pictures. Dropping a PSD on "Add a variant" for a character in Studio does the same) |
| `lim stats` | Counts the characters of dialogue and narration (by file, scene and speaker), the number of voiced lines, and spelling variant candidates ([text-stats.md](../text-stats.md)) |
| `lim i18n <language>` | Updates the translation file for that language (`lang/<language>.json`) to match the current scenarios. Exports to and imports from tables and XLIFF (`--export` `--import`, `--untranslated` `--changed`), and gives line IDs with `--stamp-ids` (chapter 10) |

`lim fmt`, `lim stats`, `lim script-export`, `lim prose`, `lim coverage` and `lim reach` treat pack scenarios (`packs/<id>/scenario`) like the main ones,
and their output gives them as `packs/<id>/scenario/<scenario>` (read with the speakers in the pack's `cast.json` too). `lim coverage` runs each pack scenario with all packs laid over the main scripts and that pack last (some packs jump to scenarios in other packs; pack data in `packs/<id>/data` is laid over too, as in the game; counted in the coverage and `--min-lines`),
and also runs from "New Game" with all packs laid over the main scripts (as in an export), showing whether the endings in pack scenarios are reached (counted in `--require-endings` too).
Give `lim reach` a place in a pack scenario (such as `packs/<id>/scenario/<scenario>:<line>`) and it searches from "New Game" with the packs laid over the same way (`lim test` doesn't run packs, so no test is suggested).
`--ending` and `--endings` also search the endings in pack scenarios.

`lim new --ci` also adds a GitHub Actions check template (`.github/workflows/liminalia-check.yml`; [ci.md](../ci.md)). As for script tests (`tests/start.limtest`), a project with the sample story gets the sample tests even without `--ci`, and a blank project (`--blank`) gets a test that only checks the game runs from start to end when `--ci` is given.

### Definitions and references (`lim query`)

`lim query [project] <label|var|asset> [name]` lists names and definition/reference counts, or the sites for a name (`start#intro`, `game.count`, `bgimage/room.png`). Sites are printed as `file:line[:column]  role  text`, definitions first. Configuration, script tests and declared project data are included. Nested variables normalize to their first property; compound assignments both read and write. Asset details include file existence, `guess` for textual matches (up to 20 per asset), and a separate `dynamic` list for expressions that could use the same asset folder.

`--json` returns `{kind, items:[{name, definitions, uses}]}` for inventories, or `{kind, name, found, candidates, definitions, uses, dynamic}` for details (`exists` for assets). Unknown names return up to three candidates and exit 1; successful queries exit 0, usage errors exit 2. Use `--lang en` for English output.

### Proofreading (`lim script-export`, `lim prose`)

**The script for proofreading.** `lim script-export` and "Script for proofreading" under Export in the Studio project settings write, for each script file, only the text
(dialogue, narration and choice text) and the scene headings. Dialogue gets the speaker name (the display name if there is `{name …}`), and ruby becomes `｜base《reading》` in text and `<ruby>` in HTML.
Commands and click waits are left out, `{br}` becomes a line break, and `{= expression}` stays as it is. Text inside `@if` branches is listed in the order written. HTML has line numbers, and `index.html` links to each file.

**Extracting and writing back the text.** `lim prose extract` extracts the text lines into one document. Each line starts with a key (`[file:line hash]`).

```
// lim prose: Edit only the text after the [ … ] at the start of each line. Don't add or delete lines.
// ruby: aozora

// file: start
[start:12 3f9a1c] Akari "We made it. Was this slope always this long?"
[start:20 0c1d2e] - Go north
```

After editing the text, `lim prose apply document` writes it back. It writes back only the lines whose original line hasn't changed since extraction (same hash)
and whose non-text parts (the kind of line, the speaker, commands, values and click waits in the text, and the jump target and parameters of a choice) haven't changed. Indentation and everything after `->` in a choice stay as they are.
Lines not written back are listed with the reason, and the exit code is 1. `--ruby aozora` (the default) turns `{r base|reading}` into `｜base《reading》` when extracting,
and turns `｜base《reading》` and `kanji《kana reading》` back into `{r …}` when writing back (`--ruby lim` keeps `{r …}`).

Text import in Studio also turns `｜base《reading》` and `kanji《kana reading》` into `{r base|reading}`.

### Script tests (`lim test`)

Put `.limtest` files in the project's `tests/`, and write the choices to make and what should happen then. `lim test` runs them from "New Game" without a screen and checks
(like Ren'Py's testcase and Yarn Spinner's test plans). One file can hold any number of tests, each starting with `# name`.

```
// Taking the north road raises Yui's trust and reaches the good ending
# North road
choose Look through the telescope
choose Take the north road
choose 2
expect game.trust == 2
expect reach ending#good
expect text "I can see the stars"
expect no-errors

# From partway, with values set
from chapter2#start
set game.trust = 5
choose Trust her
expect ending good
```

| Line | Meaning |
|---|---|
| `# name` | The start of a test. The name appears in the results |
| `from location` | Where to start (`file` or `file#label`). If omitted, `entry` in liminalia.json |
| `from-state file.json` | Start from a save (the `save` of `lim trace --json` output, or save data itself; a path relative to the test file) |
| `set variable = expression` | A value set before starting (`game.` `system.` `temp.`; takes priority over initial values) |
| `seed number` | The random seed (default 1) |
| `choose text` / `choose number` | What to choose at choices, used in the order written. Text matches the same text, or a choice containing it. Numbers count from 1 at the top (the same as `@choice default=`; `lim trace --choose` counts from 0) |
| `rest stop` / `rest first` / `rest rotate` | What happens after the `choose` lines run out. `stop` (default) stops at the next choice, `first` always takes the first, `rotate` takes the next one each time it comes back to the same choice |
| `limit number` | Stops after this many pages (default 5000. If the limit is reached without writing it, the test fails as one that doesn't end) |
| `expect expression` | The expression is true at the end (`expect game.trust >= 2`, `expect visits("start#north") == 1`) |
| `expect reach location` / `expect not reach location` | That location was passed (wasn't passed). The location is `file`, `file#label` or `file:line` (a test runs across files, so `#label` alone can't be written) |
| `expect text "text"` / `expect not text "text"` | The text (or name box) of some page contains that text (none does) |
| `expect ending kind` | It ended with an ending of that kind (`ending=` of a command that ends the playthrough, such as `bad`). With text that isn't a kind, it ended with an ending whose name (`title=`) contains that text |
| `expect end` | It ran to the end of the script or to a command that ends the playthrough (such as `@title-screen`), and didn't stop because the choices ran out or the page limit was reached |
| `expect no-errors` / `expect no-warnings` | No runtime errors (with `no-warnings`, no warnings either). Errors fail the test even if this isn't written |

- Indentation is only for looks. `//` lines are comments. Each test runs as a newly started playthrough (`system.` starts from its initial values too).
- A failure shows the line in the test file and what differed (the values of the variables in the expression, a choice that wasn't there, `choose` lines that weren't used, and so on).
- Ways of choosing can be found with `lim reach` (it shows the choices that reach a place, in a form you can write as a test as is).
- Studio doesn't have a way to run tests yet (use `lim test`).

| code | Severity | Contents |
|---|---|---|
| `bad-test` | Error | A line in a `.limtest` that can't be read (a line before `# name`, an unknown word, a malformed `set` `choose` `expect reach` and so on). A test with an unreadable line doesn't pass |

### What `lim fmt` tidies

Command lines and expressions are tidied. The content of text and dialogue lines isn't changed (trailing spaces are removed, and when indentation is set, only the indentation is aligned).
"Format" in the menu of the script heading and in ⌘K in Studio tidies the same way, as one editor change (Undo reverts it).

| Target | How it's tidied |
|---|---|
| Commands | One space between the name and parameters, and between parameters. Removes `"…"` that can be removed without changing the value. Orders named parameters as in the command definition (unnamed parameters first; if the same parameter appears twice, they aren't reordered) |
| `@set` `@let` | One space on each side of `=` (and `+=` and the like) |
| Expressions | Conditions of `@if` `@elif` `@while`, values of `@set` `@let`, `@return (expression)`, and `(expression)` parameters (including `if=(…)`). One space on each side of binary operators and `?` `:` of a conditional, one space after `,`, and no spaces inside brackets, after unary `-` `!`, or around `.` (`game.n+1>2` becomes `game.n + 1 > 2`). Strings and numbers are written as they were. `{= expression}` in text isn't changed |
| `if=(expression)` | On command lines, placed after the other named parameters (at the end of the line) |
| Choices | Tidies everything after `->` (the target and parameters) in the same way as commands. The text shown isn't changed |
| Indentation | Not changed by default. With a number of spaces or `"tab"` in `fmt.indent` in liminalia.json (or `--indent`), lines are aligned one step per block level (`@if` `@while` `@with` `@choice` `@define`), text lines included (`@elif` `@else` `@end` at the depth of the block's start; full-width spaces are text and aren't changed). Nothing inside `@script` or `@html` is changed |

```json
"fmt": { "indent": 2 }
```

A project that doesn't want expression spacing tidied writes `"fmt": { "expressions": false }` (the earlier `lim fmt` behavior: only the spaces around `=` are aligned, and expressions aren't changed).

`lim fmt` doesn't remove parameters equal to the default. Those equal to the project default (`commandDefaults`) are reported as info by the syntax check (`same-as-default`),
with a fix that removes them. Files with syntax errors aren't tidied. The result has the same syntax tree as before tidying (confirmed by tests).

<!-- For anyone changing the format: the implementation rules (the registry, where conversion tables live, how to raise the save version and so on) are in docs/design/format-rules.md. When you change it, update this document and the tests at the same time. -->
