Game SDK
Cloud saves
Save any JSON per player. Progress follows signed-in players to every device, and versions stop two devices overwriting each other.
| Call | Returns |
|---|---|
sdk.save.get(key) | The saved value, or null. |
sdk.save.getEntry(key) | { key, value, version, updatedAt } or null. |
sdk.save.set(key, value, { ifVersion? }) | { version } |
sdk.save.delete(key) | Nothing. A missing key is fine. |
sdk.save.list() | [{ key, version, sizeBytes, updatedAt }] |
Saving safely from two devices
A player may have your game open on a phone and a PC. Save with the version you loaded; if the other device saved first you get VERSION_CONFLICT instead of silently losing its progress.
let { value: state, version } = (await sdk.save.getEntry('state')) ?? { value: { level: 1 }, version: 0 };
try {
({ version } = await sdk.save.set('state', state, { ifVersion: version }));
} catch (error) {
if (error.code === 'VERSION_CONFLICT') {
({ value: state, version } = await sdk.save.getEntry('state')); // the other device won; load its copy
} else throw error;
}ifVersion: 0 means "only if nothing is saved yet".
Who can save
Cloud saves need a signed-in player. For guests, save.* rejects with NOT_SIGNED_IN: keep playing, and offer "Sign in to keep your progress".
Limits: 64 KB per value, 100 keys and 1 MB per player per game, 30 saves a minute. See Errors and limits.