# Saving games

> Aego 0.12.5 · development; docs build `4a32b816933e02930662f6a443cb25abe6050d090c55e237cbff5c44ae9b25f8`. [Build manifest](/docs-build.json).

A save holds what you mark as persistent, not the whole scene. Loading a save reloads its scene from the project and then applies the save on top.

In Try it, the Checkpoint script saves after one second and then loads that save every few seconds. The green ball has Persist and comes back to where it was saved; the grey one has not and starts over from the scene file. In Try it saves stay in memory and are gone when the page closes.

| Mark | What is saved |
|---|---|
| `save.Persist` component | the node's transform and enabled flag |
| `sdk.Persist("field", …)` on a component type | those fields of every such component |
| `@persist` on a script field | that field of every script instance |
| `OnSave()` / `OnLoad()` | values the script writes with `save.Put*` |

Besides that a save remembers which scene nodes were destroyed and every object made with `scene.Spawn`: its prefab, parent, pose and persistent data.

    @persist
    var Coins int

    func OnSave() {
      save.PutVec2("checkpoint", lastCheckpoint)
    }

    func OnLoad() {
      lastCheckpoint = save.GetVec2("checkpoint", node.Position())
    }

| Function | |
|---|---|
| `save.Save(slot)` | write the game to a slot at the end of the frame |
| `save.Load(slot)` | reload the saved scene and restore the slot |
| `save.Checkpoint()` | save to the slot `checkpoint` |
| `save.Autosave(seconds)` | save to `autosave` every given number of real seconds |
| `save.Exists(slot)`, `save.Delete(slot)` | |
| `save.SetGlobalInt(key, v)`, `save.GlobalInt(key, def)` | game-wide progress carried by every save; also Float, Bool, String |

Slot names use letters, digits, `-` and `_`. Saves live next to the player settings, in `saves/` of the profile.
