API Reference › Builtin functions › load
function

load

load() -> bool

Restores the entire world from the snapshot most recently written by save() — every model instance, property, and program var returns to its saved state. It returns a bool: true when a snapshot existed and was restored, false when there was nothing to load, so you can guard the call and avoid clobbering the current world by mistake. Use it for quick-load, respawning at a checkpoint, or resetting a test to a known state. It takes no arguments.

Example

program QuickLoad {
  property Position { column: int = 0, row: int = 0 }
  model Player { Position }

  handler SpawnPlayer phase Start {
    spawn Player { Position { column: 5, row: 5 } }
    save()
  }

  handler ReadInput phase Input {
    if Input.key() == 'r' {
      let restored = load()
      if restored { print(1) }
    }
  }

  handler DrawWorld phase Render {
    Screen.clear(Color.MidnightBlue)
    Screen.show()
  }
}
← All symbols