# Importing & Exporting Scripts

### The KTN1 token format

Every script you import or export is packaged as a **KTN1 token** — a single line of text that starts with `KTN1` followed by compressed, encoded data. It contains exactly three things:

| Field | Meaning |
|---|---|
| `n` | the script's name |
| `c` | the full source code |
| `v` | the format version (currently always `1`) |

Nothing else is in there. No player data, no server data — just your script, generated entirely client-side in the online editor.

### Importing

```
/katton import <token>
```

* This **replaces** any existing script you own with the same name.
* Compilation happens **before** anything is saved. If your script has an error, nothing changes — your old version (if any) is untouched and keeps running.
* You will only ever import into **your own** UUID's script folder. There is no way to import a script as, or on behalf of, another player.
* Script names may only contain letters, numbers, underscores, and hyphens.

Example error output if something's wrong:

```
Import failed: Compilation failed
  greeting:error [greeting.kat:3:24] Function parameters cannot have types - use function name(a, b)
```

That tells you: script `greeting`, line 3, column 24 — go fix it and re-import.

### Exporting

```
/katton export <script-name>
```

This gives you back a KTN1 token for one of your **own** scripts, so you can:

* paste it back into the online editor to keep editing,
* move it to a different server,
* back it up somewhere safe.

You can only export scripts you own.

### Limits to know about

| Limit | Default |
|---|---|
| Max scripts per player | 25 |
| Max script source size | 256 KB |
| Max compressed token size | 64 KB |
| Max decompressed payload size | 1 MB |

If you hit the script-count limit, delete an old one first with `/katton delete <name>`.

### Deleting a script

```
/katton delete <script-name>
```

You have to run this command **twice in a row** to confirm — the first run just warns you:

```
Run '/katton delete greeting' again to permanently delete this script.
```

This also cancels every scheduled task that script had running, and clears its persistent state (`Katton.vars`).
