Save data
The data module persists player data across sessions and devices. For signed-in users, data syncs through Funox; for guests, it's stored in localStorage and migrated on sign-in.
Limits
- Maximum 1 MB of total stored data per game per player.
- Saves are debounced ~1 second — frequent
setItemcalls batch into one write. - In high-volume periods, the debounce can stretch up to 30 seconds.
- Exceeding the size limit returns the
dataLimitExceedederror.
setItem(key, value)
Store a string value under a key.
1window.Funox.SDK.data.setItem("highScore", "12450");2window.Funox.SDK.data.setItem("inventory", JSON.stringify(items));Use JSON.stringify for objects, arrays, numbers, and booleans.
getItem(key)
Retrieve a value by key. Returns null if the key doesn't exist.
1const score = window.Funox.SDK.data.getItem("highScore");2const items = JSON.parse(window.Funox.SDK.data.getItem("inventory") ?? "[]");removeItem(key)
Delete a single key.
1window.Funox.SDK.data.removeItem("inventory");clear()
Delete all stored data for the current player in your game. Use cautiously.
1window.Funox.SDK.data.clear();Guest vs. signed-in
| State | Storage | Sync |
|---|---|---|
| Guest | localStorage | None |
| Signed in | Funox cloud | Yes, across devices |
When a guest signs in, all guest data automatically migrates to their account. No code needed.
Don't sync this key
Prefix keys you don't want to sync (debug flags, device-specific settings) with funox_ignore_:
1window.Funox.SDK.data.setItem("funox_ignore_lastDevice", "iPhone");Funox-ignored keys stay in localStorage only.
Best practices
- Save on meaningful state changes, not every frame.
- Read once at game boot — cache the values in memory.
- Version your save format (
{ version: 2, ... }) so you can migrate later. - Don't store anything sensitive — clients can read their own save data.
1function loadSave() {2 const raw = window.Funox.SDK.data.getItem("save");3 if (!raw) return defaultState();4 5 const save = JSON.parse(raw);6 if (save.version === 1) return migrateV1(save);7 return save;8}9 10function persistSave(state) {11 window.Funox.SDK.data.setItem("save", JSON.stringify({12 version: 2,13 ...state,14 }));15}Engine-specific helpers
Some engines provide typed wrappers:
| Engine | Methods |
|---|---|
| Unity | SetInt / GetInt, SetFloat / GetFloat, SetString / GetString, HasKey, DeleteKey, DeleteAll |
| GameMaker | funox_data_set_item, funox_data_get_item, funox_data_remove_item, funox_data_clear |
| Godot | data_set_item, data_get_item, data_has_key |
See your engine guide for details.