# Play an exported game to the end automatically

> Use lim playtest to have the exported browser version play automatically from New Game to the end, and report errors and where it got stuck

You can check whether an exported game plays through to the end with `lim playtest`. It opens the exported browser version, starts from "New Game" and keeps advancing without stopping. It runs several times, choosing differently at the choices.

## Run it

In the project folder, run the following command. With `--rebuild`, it exports the browser version first.

```bash
lim playtest --rebuild --runs 2
```

![The output of lim playtest (in Japanese), showing that both runs reached the end.](/shots/en/h-playtest-ok.webp)

| Option | What it sets |
|---|---|
| `--runs 3` | The number of runs |
| `--choose 1,0` | The options to pick at choices (counted from 0). Once these run out, each run picks differently |
| `--stuck 20` | It counts as "stuck" if the page doesn't advance for this many seconds |
| `--timeout 600` | Cuts a run off after this many seconds |
| `--json` | Outputs the results as JSON |
| `--lang en` | Prints the results in English |

Pass an export folder to run that browser version (`lim playtest . dist/browser/…`). If you leave it out, the newest export is used.

## When it gets stuck

When neither the page nor the position advances, it shows where it stopped (the file and line) and saves the screen at that moment as `playtest/run-1.png` and so on in the output folder. It also reports page errors, console errors and files that couldn't be loaded. If there's even one of these, the command ends in failure.

Screens that don't advance just by clicking, such as text input or a game's own mini-games, also show up as places where it got stuck.

## Play faster (`--fast`)

With `--fast`, waits are cut to 1/20, and animations that have an end play 20 times as fast. Animations that loop forever are left as they are.

```bash
lim playtest --fast --runs 3
```

Waits for assets to load get shorter too, so if a run with `--fast` gets stuck, run it again without it to check.

## Keep a record of the run (`--log` and `--shots`)

With `--log`, one line is recorded for each page that waits for a click, in `playtest/run-1.jsonl` and so on in the output folder. Each line has the page's position (file and line), the name box, the text, the voice, and the background, sprites (variant and position), BGM and so on at that moment. For choices, it has the options shown and the number picked. You can look up later what was on screen at which line.

With `--shots`, in addition to the `--log` record, a screenshot (JPEG) is taken into `playtest/run-1/` and so on for each page where the background, an image or a sprite changed, and for each choice. The files are named like `0001_start_12.jpg`, with the number, file and line in that order, and choices get `_choice`.

```bash
lim playtest --shots --timeout 1200
```

- The record and screenshots from the previous run are removed before writing.
- Taking screenshots takes time. For long games, raise `--timeout` too.

## Avoid bad endings (`--avoid-ending` and `--avoid-choice`)

When you run with different choices several times, some runs may end in a bad ending early and never reach the scenes after it. With `--avoid-ending`, a choice that can only lead to a bad ending isn't picked when there's another choice to pick.

```bash
lim playtest --avoid-ending --runs 3
lim playtest --avoid-ending bad,lost --avoid-choice "Fall asleep,Run away"
```

- The kind of ending is the kind written in `ending=` of `@title-screen` (`@title-screen ending=bad`). If you leave out the value of `--avoid-ending`, the kind `bad` and endings whose name contains `DEAD END`, `GAME OVER`, `デッドエンド` or `ゲームオーバー` are avoided. With text that isn't a kind, endings whose name (`title=`) contains that text are avoided.
- At the start, it shows the endings it avoids and their scenes. If nothing matches, it says so.
- `--avoid-choice` doesn't pick a choice containing the text you write when there's another choice to pick.
- Whether to avoid a choice is decided from how the scripts connect (the flowchart). A choice leading to a scene where a condition can also lead to another ending isn't avoided. Avoid bad endings decided by the values of variables with `--avoid-choice`.
- Choices decided with `--choose` don't change.
- The results show how many choices were avoided.

To use these every time, write them in `playtest` in `liminalia.json`.

```json
{ "playtest": { "avoidEndings": ["bad"], "avoidChoices": ["Fall asleep"] } }
```

## How it differs from Studio's all-routes test

The all-routes test on Studio's "Check" screen runs the scenario without a screen and follows the branches. `lim playtest` runs the exported game itself in Chromium, so it also finds problems you can only discover after export, such as assets missing from the export or an encrypted game that won't open.

To run it on every push in CI, see [Check the scenario in CI](/en/howto/ci/).
