# Writing scenarios

### 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) |
