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): Serializesdataas JSON (auto-appending.jsonwhennamehas no extension) and writes atomically via a.json.tmpfile + rename inside the per-game OS user-data directory.pite.load(name: str, default=None): Reads and parses the saved JSON file, returningdefaultif the file does not exist and raisingRuntimeErrorif the file is corrupt.pite.user_path(rel: str = "") -> str: Resolves auser://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(path: str): Validates the target scene immediately (res://...or relative path; raisesValueErrororFileNotFoundErrorif 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 bothpite runand packed exports.pite.reload_scene(): Queues a deferred reload of the currently active scene at the end of the current frame.