Data Module
This page explains how to use the Playol SDK’s data module to store and synchronize game data across devices — without any backend setup. It supports reading and writing structured data like save progress, configuration, and achievement status.
The data module provides a platform-hosted sync mechanism that allows developers to persist player progress, settings, and other structured data tied to their identity. All data is bound to the current user account and can sync across devices automatically.
📌 1. Use Cases
- Store level progress, settings, temporary game states, event triggers, etc.;
- No backend database needed — all data is hosted by the platform;
- Players can resume progress on any device after login (cloud save);
- All data is bound to
userIdand accessible only in login state; - Supports structured values with a per-user limit of 1MB;
- All method calls are made synchronously.
🧩 2. Methods & Usage
📥 Get Data
get(k)
Retrieve the value for a specific key.
const level = window.playolSDK.data.get('currentLevel')
console.log(level)getAll()
Retrieve all stored data for the current user as a key-value object.
const allData = window.playolSDK.data.getAll()
console.log(allData)📤 Set Data
set(k, v)
Save a value for a specific key. Supports various data types and syncs automatically.
| Parameter | Type | Required | Description |
|---|---|---|---|
k | string | ✅ | Key name |
v | string | number | boolean | object | ✅ | Any valid value |
window.playolSDK.data.set('musicOn', true)
window.playolSDK.data.set('currentLevel', 12)
window.playolSDK.data.set('config', { speed: 3, volume: 0.8 })📌 Notes:
- All set operations trigger sync with the platform (with throttling);
- Avoid excessive calls — batch changes where possible.
❌ Delete Data
del(k)
Delete a specific key and sync changes to the platform.
window.playolSDK.data.del('config')🧹 Clear All Data
clear()
Erase all stored data for the current user. Use with caution.
window.playolSDK.data.clear()📌 Notes:
- This operation is irreversible — typically used during logout or account reset;
- Always confirm user intent before calling.
⚙️ 3. Sync Mechanism Explained
- All
set,del, andclearactions trigger automatic data uploads; - The SDK uses debounced sync — changes within 1 second are batched; max delay is 30 seconds;
- Each user has a 1MB storage limit — if exceeded, uploads are halted and warnings logged;
- Sync is tied to the authenticated account — guest users do not benefit from cross-device sync.
🛠️ 4. Recommended Usage Patterns
| Scenario | Suggested Method |
|---|---|
| Save current level | set('currentLevel', 5) |
| Load all config | getAll() |
| Remove a single setting | del('volume') |
| Full game reset | clear() |
| Auto-save after UI change | Call set() after interaction |
| Fetch progress on load | get() / getAll() |
📦 5. FAQ
Q: Is data saved in real time?
A: The SDK syncs automatically. Uploads are triggered within ~1s, but no later than 30s.
Q: Will set() overwrite existing data?
A: Yes. Repeated calls with the same key will overwrite the previous value.
Q: Can guest users use the data module?
A: Yes, but only for local use — cloud sync is not available for guests.
Q: Will I be notified if storage fails?
A: Yes. Warnings or errors (e.g., size exceeded) will be logged in the browser console.
🔗 Related Docs
👉 User Module | Game Module | Payment Module | Invite Module