# Writing scenarios

### 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]`.
