Skip to content
Edit this page

Persistence & Scene Transitions

Pite provides built-in APIs for per-game user save data (user://) and deferred end-of-frame scene switching.


User Save Data

save_data = pite.load("slot1", {"hp": 100, "level": 1})
save_data["hp"] -= 10
pite.save("slot1", save_data)

notes_file = pite.user_path("user://notes.txt")

API Reference

  • pite.save(name: str, data): Serializes data as JSON (auto-appending .json when name has no extension) and writes atomically via a .json.tmp file + rename inside the per-game OS user-data directory.
  • pite.load(name: str, default=None): Reads and parses the saved JSON file, returning default if the file does not exist and raising RuntimeError if the file is corrupt.
  • pite.user_path(rel: str = "") -> str: Resolves a user:// URI or relative path inside the user-data directory and creates parent directories for custom file I/O. Rejects .. traversal, null bytes, and absolute paths.

Platform Locations

OS Resolved user:// Directory
Linux $XDG_DATA_HOME/pite/<game> or ~/.local/share/pite/<game>
macOS ~/Library/Application Support/pite/<game>
Windows %APPDATA%\pite\<game>

Scene Transitions

pite.change_scene("res://scenes/level2.ptscn")
pite.reload_scene()
  • pite.change_scene(path: str): Validates the target scene immediately (res://... or relative path; raises ValueError or FileNotFoundError if invalid or missing) and queues a deferred scene switch applied safely at the end of the current frame. Autoload plugins are preserved across transitions, and transitions work identically in both pite run and packed exports.
  • pite.reload_scene(): Queues a deferred reload of the currently active scene at the end of the current frame.