# aego/save

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

`Save` and `Load` take effect at the end of the frame. `Put*` belong in `OnSave` and `Get*` in `OnLoad`; their keys belong to the node. `SetGlobal*` values are carried by every save. The documentation sandbox has no saves, so this example needs a project. See [Saving games](/save.md).

## Example

```aes check
package demo

import (
    "aego/log"
    "aego/save"
)

script Checkpoints {
    var reached int
    var frames int

    func Ready() {
        log.Info("runs so far " + string(save.GlobalInt("runs", 0)) + ", slot1 exists: " + string(save.Exists("slot1")))
        save.SetGlobalInt("runs", save.GlobalInt("runs", 0) + 1)
    }

    func Update(dt float) {
        frames++
        if frames == 30 {
            reached = 2
            node.SetPosition(Vec2{5, 0})
            save.Save("slot1")
            log.Info("saved at checkpoint " + string(reached))
        }
        if frames == 31 {
            log.Info("slot1 exists: " + string(save.Exists("slot1")))
        }
    }

    func OnSave() {
        save.PutInt("reached", reached)
        save.PutVec2("respawn", node.Position())
    }

    func OnLoad() {
        reached = save.GetInt("reached", 0)
        node.SetPosition(save.GetVec2("respawn", Vec2{}))
        log.Info("loaded checkpoint " + string(reached))
    }
}
```

## Autosave

```
func Autosave(seconds float)
```

Saves to the slot named autosave every given number of real seconds; 0 turns it off.

## Checkpoint

```
func Checkpoint()
```

Saves the game to the slot named checkpoint.

## Delete

```
func Delete(slot string)
```

Removes a save and its preview.

## Exists

```
func Exists(slot string) bool
```

Reports whether a slot holds a save.

## GetBool

```
func GetBool(key string, def bool) bool
```

Reads a value this node stored, or def; it works in OnLoad.

## GetFloat

```
func GetFloat(key string, def float) float
```

Reads a value this node stored, or def; it works in OnLoad.

## GetInt

```
func GetInt(key string, def int) int
```

Reads a value this node stored, or def; it works in OnLoad.

## GetString

```
func GetString(key string, def string) string
```

Reads a value this node stored, or def; it works in OnLoad.

## GetVec2

```
func GetVec2(key string, def Vec2) Vec2
```

Reads a value this node stored, or def; it works in OnLoad.

## GlobalBool

```
func GlobalBool(key string, def bool) bool
```

Reads game-wide progress, or def.

## GlobalFloat

```
func GlobalFloat(key string, def float) float
```

Reads game-wide progress, or def.

## GlobalInt

```
func GlobalInt(key string, def int) int
```

Reads game-wide progress, or def.

## GlobalString

```
func GlobalString(key string, def string) string
```

Reads game-wide progress, or def.

## Load

```
func Load(slot string)
```

Reloads the saved scene and restores the slot at the end of the frame.

## PutBool

```
func PutBool(key string, value bool)
```

Stores a value for this node; call it in OnSave.

## PutFloat

```
func PutFloat(key string, value float)
```

Stores a value for this node; call it in OnSave.

## PutInt

```
func PutInt(key string, value int)
```

Stores a value for this node; call it in OnSave.

## PutString

```
func PutString(key string, value string)
```

Stores a value for this node; call it in OnSave.

## PutVec2

```
func PutVec2(key string, value Vec2)
```

Stores a value for this node; call it in OnSave.

## Save

```
func Save(slot string)
```

Writes the game to a slot at the end of the frame.

## SetGlobalBool

```
func SetGlobalBool(key string, value bool)
```

Stores game-wide progress that every save carries.

## SetGlobalFloat

```
func SetGlobalFloat(key string, value float)
```

Stores game-wide progress that every save carries.

## SetGlobalInt

```
func SetGlobalInt(key string, value int)
```

Stores game-wide progress that every save carries.

## SetGlobalString

```
func SetGlobalString(key string, value string)
```

Stores game-wide progress that every save carries.
