# The Splat Labs course format

This is how a Cooper Academy course is written for the Splat Labs API. Courses teach kids, about 9 years old, to make games with Splat Script, or to type with typing games. The author is a grown-up, but the readers are kids: write in short sentences and plain words, with one idea to a paragraph and a subheading every few paragraphs.

## The shape

A course is JSON. Save it with `PUT /api/v1/my/courses/{id}`.

| Field | What it is | Limits |
| --- | --- | --- |
| `title` | The course's name | 1 to 120 characters |
| `summary` | What the course is about, in a sentence or two | Up to 400 characters |
| `content.chapters` | The chapters, in order | Up to 60 |
| `chapters[].id` | The chapter's id. Never change it | 1 to 32 characters |
| `chapters[].title` | The chapter's name | 1 to 120 characters |
| `chapters[].parentNote` | Optional. Markdown for the parent: what the chapter teaches, how long it takes, what the child makes. Students never see it | Up to 100,000 characters |
| `chapters[].optional` | Optional. `true` makes every section in the chapter optional (below) | true or false |
| `chapters[].sections` | The sections, in order | Up to 60 a chapter |
| `sections[].id` | The section's id. Never change it | 1 to 32 characters |
| `sections[].title` | The section's name, shown as its heading | 1 to 120 characters |
| `sections[].kind` | How a student finishes it (below) | One of: reading, signup, try, challenge, quiz, video |
| `sections[].markdown` | What the section says (below) | Up to 100,000 characters |
| `sections[].optional` | Optional. `true` makes the section optional (below) | true or false |

Every chapter and section id must be different from every other in the course. Ids keep students' progress and links working, so keep a part's id when you rename or move it, and make a new id only for a new part. The whole course may be at most 2,000,000 bytes as JSON.

## Section kinds

A section must hold what its kind needs, or students can never finish it. The API won't publish a course where one doesn't.

| Kind | How the student finishes it | What it must hold |
| --- | --- | --- |
| `reading` | Presses Done | Anything |
| `video` | Presses Done | A YouTube video |
| `try` | Presses Play in a code widget, or starts a typing game | A code widget or a typing game |
| `quiz` | Answers every question right | A quiz |
| `challenge` | Passes every test, and reaches every typing game's goal | A code widget with tests, a game button, or a typing game |
| `signup` | Has a Lab (a Lab Key or an account) | Anything, usually words about getting a Lab |

### Optional chapters and sections

An optional section has no tick: the student reads it, or skips it, and presses Next. A student finishes the course, and gets the certificate, when every section that isn't optional is ticked, even with optional sections still ahead. Use it for extra reading, such as a last chapter of "more to explore".

Set `"optional": true` on a section, or on a chapter to make all its sections optional. A section in an optional chapter is optional whatever it says. A course needs at least one section that isn't optional, and a `signup` section can never be optional.

## What section Markdown can hold

Only these. No HTML, and no other fences.

- Headings with `##`, `###` and `####`. Never `#`: the section's title is already its top heading, so don't repeat it.
- Paragraphs, **bold**, *italic*, `inline code`, [links](https://splatlabs.games), lists with "- " or "1. ", and tables.
- A quote (`> words`) shows as one of Cooper's tips.
- A picture by its address: `![what it shows](https://example.com/picture.png)`.
- A small picture of one of the builder's own buttons, in a line of words, straight after the words that name it: `Press the **Game** button ![](art:builder.settings-button.game-settings), under the map.` Every picture and its id is listed at https://splatlabs.games/help/writing-courses#courses.button-pictures. An id that isn't in that list shows nothing.
- A YouTube video: `![](youtube:VIDEOID)`, with the video's 11-character id.

### Code widgets

A script the student can change and play, with a little game:

````
```script for platformer enemy
when I see {Hero}
  jump
```
````

After `for` comes who runs the script, with the game first: `platformer` or `adventure`, then the character. Platformer characters: enemy, hero, level, game, block, object, boss. Adventure characters: hero, level, game, villager, thing, walkway. Always write `for`. Add `as` and a character's name to choose who shows in the little game, as in `for platformer enemy as slime`. A Platformer has slime and bubble in every biome; without `as` it shows the boar. An Adventure has slime, bubble, soot, mushroom, gremlin and soldier. End with `with 3 hits` (1 to 9) to make a Platformer enemy take that many hits: otherwise one hit beats it, so `when I get hit` never runs and `my health` is always full.

- ````script edit for …` is a widget the student can add steps to, drag steps about in and type in. A plain widget only lets them swap a word from a list and type inside quotes.
- ````script only for …` is a widget with no game: only the script's problems and log.
- ````script tabs for …` is a widget with a tab for each script.
- A fence with no `script`, such as ````for platformer enemy`, is a script to read only.
- ````text` holds plain words that aren't a script.

Splat Script words never use apostrophes. Look words up in the Splat Labs help at https://splatlabs.games/help rather than making them up.

### Tests (challenges)

Tests go in a `test` fence right under a code widget. They make it a challenge: the student finishes it when every test passes.

````
```test
when the game is won
  test "The hero wins with some health left" if the {Hero} health is over 0
```
````

### Quizzes

Each question is a line, then its answers. "- " starts a wrong answer and "* " a right one. A line indented by two spaces under an answer is what the student reads after picking it. Every question needs at least one right answer.

````
```quiz
What does a "when" line do?

- Makes the hero jump
  Not quite. It waits for something to happen.
* Starts a rule when something happens
  Yes. A "when" line says when a rule runs.
```
````

### Game buttons

A button that makes a game in the student's Lab, which they build in for a challenge. The first line is `new game`, or `clone` and the id of one of your own games to give each student a copy. The `id` line is the button's own key: 4 to 32 letters, digits, - or _, different for every button, and never changed. The last line is the button's words.

````
```game
new game
id k3J9xQ2m
Make your game
```
````

### The builder widget

The game builder itself, on the course page, with the student's game in it. The student builds without leaving the section, and a challenge ticks the moment the game's tests pass. The first line is `builder`. Give it the `id` of the game button that made the student's game, and it opens the same game; with an id of its own, its first press makes a new game. It counts as a game button, so a challenge section may hold one. On a phone-sized screen it shows as a plain button that opens the builder on its own page.

````
```game
builder
id k3J9xQ2m
```
````

### The Addon Lab widget

The Addon Lab itself, on the course page. The first time, the student answers its questions there to make an addon, and that addon stays theirs for the widget: after that, it opens with it. It is one of their addons, like any they make. The fence is ```addon, its first line is `builder`, and the `id` line is the widget's own key (4 to 32 letters, digits, - or _). Give a widget in a later section the same id to open the same addon. An optional last line is the button's words. It doesn't finish a challenge. On a phone-sized screen it shows a note instead.

````
```addon
builder
id p7Wc2rTa
Open your coin here
```
````

### Typing games

A typing game, where the student types to play: ```typing and the game. There are four:

| Game | What the student types | What happens |
| --- | --- | --- |
| `runner` | A word for each enemy, or whole sentences | The hero jumps each enemy; the end of a sentence is a big leap |
| `rain` | The letter on each falling coin | The hero catches the coin |
| `stomp` | The word over a walking enemy | The hero stomps it |
| `boss` | A sentence before the boss's attack | The hero hits the boss; one notch of health for each sentence |

Every game starts with the student's fingers on the home keys and the space bar. Words and sentences are drawn from our kid-safe word list, using only the lesson's keys, or the author lists them. A sentence can run over more than one line: an indented line under an item carries it on, and the student presses Enter there.

````
```typing runner
id: home-row-run
keys: asdf jkl
goal: 15 words
```
````

````
```typing boss
id: first-boss
biome: bubble bog
description: The boss is angry! Type fast to beat it.
sentences:
- Cooper has two bandages on his beak.
  Vix can jump over the moon.
- The quick brown fox jumped over the lazy moon.
```
````

Each line is a `name: value` setting, or a `- ` item in a list. Everything after the first `: ` or `- ` is typed exactly as written: there is no quoting, and a `#` or a colon in a sentence is just part of it. Spaces before a `- ` don't matter. An indented line that isn't an item carries on the line above: in a sentence it is an Enter, anywhere else a space.

| Setting | What it does | Default |
| --- | --- | --- |
| `id:` | The game's own key, for its best score: 4 to 32 letters, digits, - or _. Never changed | Required |
| `keys:` | The keys the drawn words may use, such as `asdf jkl` | Every letter |
| `words:` then `- ` items | Exact words. Not for a boss | Drawn from `keys:` |
| `sentences:` then `- ` items | Exact sentences, for a runner or a boss | Ones we wrote for the keys |
| `goal:` | Such as `15 words`, `20 letters` (rain) or `3 sentences`. A boss's goal is always its sentences | 15 words, 20 letters, 12 words, 3 sentences |
| `pace:` / `max pace:` | Starting and highest speed, in words a minute | 8 / 40 |
| `timer:` | `off` makes the game wait for every word | `on` |
| `biome:` | The background, enemies and boss: Green Hills, Graveyard, Space, Dragon World, Ice World, Sunflower Hills, Bubble Bog, Junkyard | Green Hills |
| `description:` | A line shown before the game starts | None |

A typing game's words should only use keys the course has taught by then. With `keys:`, the check lists any word or sentence that uses a key outside them.

## Checking

`POST /api/v1/my/courses/{id}/check` lists every problem without saving: a missing name, two parts with the same id, a quiz with no right answer, a script the game can't read, or a section that doesn't hold what its kind needs. Each problem says where it is, such as `content.chapters[0].sections[2].markdown`.

## A whole example

```json
{
  "title": "Make an enemy jump",
  "summary": "Write your first Splat Script and make a Platformer enemy jump.",
  "content": {
    "chapters": [
      {
        "id": "ch1",
        "title": "Your first script",
        "parentNote": "Your child writes a two-line script. It takes about 15 minutes.",
        "sections": [
          {
            "id": "s1",
            "title": "What is a script?",
            "kind": "reading",
            "markdown": "A script tells a character what to do.\n\n## Rules\n\nEach rule starts with **when**.\n\n> Tip: you can always press Play to try your script."
          },
          {
            "id": "s2",
            "title": "Try it",
            "kind": "try",
            "markdown": "Press Play, then walk up to the enemy.\n\n```script for platformer enemy\nwhen I see {Hero}\n  jump\n```"
          },
          {
            "id": "s3",
            "title": "Check what you learned",
            "kind": "quiz",
            "markdown": "```quiz\nWhen does a \"when\" rule run?\n\n- Before the game starts\n  Not quite. It waits for something to happen.\n* When something happens\n  Yes. A when rule waits for its moment.\n```"
          }
        ]
      }
    ]
  }
}
```
