# Scripts

> When a sentence is not enough, write JavaScript against the game API.

Most games need no code. When a rule does, add a script.

![An expression script in the editor returning the higher of RedScore and BlueScore, with its result type in the Inspector.](/shots/script-editor.png)

## Two kinds

- **Action script**: runs as an action, _Run script {script}_.
- **Expression script**: returns a value for any slot of its **Result** type.

The editor knows your project: variables, objects and events autocomplete.

## What a script can use

| Name                  | What it is                                         |
| --------------------- | -------------------------------------------------- |
| `game`, `world`, `ui` | The game API ([reference](/reference/game))        |
| `math`                | Vectors and helpers ([reference](/reference/math)) |
| `vars`                | Game variables by name                             |
| `objects`, `prefabs`  | Your objects and prefabs by name                   |
| `events`, `enums`     | Custom events and enumeration values               |
| `roles`, `actions`    | Roles and control actions                          |
| `bound`               | What the row's trigger gives, like `bound.player`  |

## Rules

- No clocks, no network, no `Math`: every player must see the same game.
  Use `math` for numbers, and `math.seed(game.seed)` for random draws that
  change every match.
- A syntax error counts in Problems. An error while the game runs shows in
  the Play log as _Script name: …_; click it to open the script.
