# Generate twenty quests from a table

> Write many similar quests from a list in a script, and save the file only when it passes the checks.

You have a list, programs to install or habits to keep, and you want one quest per row without writing twenty blocks by hand.

## Solution

Add the SDK to your project as in [Check a file from a Node script](https://docs.altasystem.ai/recipes/validate-from-node), then save this script as `generate-quests.mjs`:

```js [generate-quests.mjs]
// Writes one quest per row of a table into a quest file, checks it, and saves it only if it passes.
// Usage: node generate-quests.mjs my-pack/tools.json
import { writeFileSync } from "node:fs";
import { formatProblem, validate } from "@altasystem/sdk";

// One row per program: its command, then its name in English and in French.
const TABLE = [
  ["git", "Git", "Git"], ["node", "Node.js", "Node.js"], ["python3", "Python", "Python"], ["jq", "jq", "jq"],
  ["rg", "ripgrep", "ripgrep"], ["fd", "fd", "fd"], ["ffmpeg", "FFmpeg", "FFmpeg"], ["gh", "GitHub CLI", "la CLI GitHub"],
  ["tmux", "tmux", "tmux"], ["htop", "htop", "htop"], ["wget", "wget", "wget"], ["tree", "tree", "tree"],
  ["bat", "bat", "bat"], ["fzf", "fzf", "fzf"], ["sqlite3", "SQLite", "SQLite"], ["pandoc", "Pandoc", "Pandoc"],
  ["yt-dlp", "yt-dlp", "yt-dlp"], ["imagemagick", "ImageMagick", "ImageMagick"], ["uv", "uv", "uv"], ["deno", "Deno", "Deno"],
];

const quest = ([bin, en, fr]) => ({
  id: `tool-${bin}`,
  uid: `core.my-pack.tool-${bin}`,
  act: 1,
  giver: "operator",
  title: { en: `Have ${en} at hand`, fr: `Avoir ${fr} sous la main` },
  reward: { xp: 20 },
  steps: [{
    id: "installed",
    kind: "check",
    title: { en: `${en} is installed`, fr: `${fr} est installé` },
    check: { type: "bin", name: bin },
  }],
});

const file = process.argv[2] ?? "my-pack/tools.json";
const doc = { schema: "alta.quests/0.3", branch: "core", quests: TABLE.map(quest) };
const result = validate(doc);

for (const p of result.problems) console.log(formatProblem(p, file));
if (result.ok) {
  writeFileSync(file, JSON.stringify(doc, null, 2) + "\n");
  console.log(`wrote ${doc.quests.length} quests to ${file}`);
} else process.exitCode = 1;
```

Run it next to your pack, then check the pack:

```sh [Terminal]
node generate-quests.mjs my-pack/tools.json
alta lint my-pack
```

```text [Output]
wrote 20 quests to my-pack/tools.json
ok   my-pack/quests.json (quests)
ok   my-pack/tools.json (quests)
2 checked, 0 errors, 0 warnings
```

## How it works

Each row becomes a quest with one `check` step: a [bin check](https://docs.altasystem.ai/reference/standards/checks#bin) completes it as soon as the program is installed, so the player never clicks "I did it". The script checks the whole document with `validate` before writing it, so a typo in the table (two rows with the same command, a program name with a capital letter) stops the script instead of producing a broken file. `alta lint` then checks the new file with the rest of your pack.

## Variants

- **Let the game install it.** Make the step an `action` that runs `pkg.install`; its program must be in that executor's closed list. See [Executors](https://docs.altasystem.ai/reference/standards/executors#pkg-install).
- **From a spreadsheet.** Export it as CSV and build `TABLE` from the lines of the file.
- **Builders.** `actionStep` and `humanStep` of the SDK build valid steps that do something; `stepProblems` checks steps alone.

**Next:**

- [Make a step that does it](https://docs.altasystem.ai/guides/quests/do-it-step)
- [Executors](https://docs.altasystem.ai/reference/standards/executors)
