Cloud save
Store per-player JSON documents under keys, with revisions so two devices never silently overwrite each other.
On this page
Save#
Save any serializable object (Unity) or JSON value under a key. Each save gets the next revision number.
[System.Serializable]
public class Progress { public int level; public int coins; }
var saved = await Majacloud.CloudSave.SaveAsync("progress", new Progress { level = 3, coins = 120 });
if (saved.Ok) Debug.Log("Saved revision " + saved.Value.Revision);var saved := await Majacloud.cloud_save.save("progress", {"level": 3, "coins": 120})
if saved.ok:
print("Saved revision ", saved.value.revision)const saved = await mc.cloudSave.save('progress', { level: 3, coins: 120 });
if (saved.ok) console.log('Saved revision ' + saved.value.revision);curl -X PUT https://majacloud.majanite.com/v1/cloud/progress -H "X-Project-ID: $PROJECT_ID" -H "X-Client-Key: $CLIENT_KEY" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" -d '{"data": {"level": 3, "coins": 120}}'Load#
Loading a key that was never saved returns not_found: treat it as the first launch.
var loaded = await Majacloud.CloudSave.LoadAsync<Progress>("progress");
if (loaded.Ok) progress = loaded.Value.Data;
else if (loaded.IsNotFound) progress = new Progress(); // first launchvar loaded := await Majacloud.cloud_save.load_save("progress")
if loaded.ok:
progress = loaded.value.data
elif loaded.is_not_found():
progress = {} # first launchconst loaded = await mc.cloudSave.load('progress');
if (loaded.ok) progress = loaded.value.data;
else if (loaded.error.code === 'not_found') progress = {}; // first launchcurl https://majacloud.majanite.com/v1/cloud/progress -H "X-Project-ID: $PROJECT_ID" -H "X-Client-Key: $CLIENT_KEY" \
-H "Authorization: Bearer $TOKEN"Revisions and conflicts#
Pass the revision you loaded as the expected revision. If another device saved in the meantime, the save fails with revision_mismatch and details.current_revision; load again, merge and retry. An expected revision of 0 means create only.
// Only overwrite the revision we loaded; another device may have saved since
var safe = await Majacloud.CloudSave.SaveAsync("progress", progress, expectedRevision: loaded.Value.Revision);
if (!safe.Ok && safe.Error.Code == MajacloudErrorCode.RevisionMismatch)
{
// Load again, merge, and save with the new revision
}# Only overwrite the revision we loaded; another device may have saved since
var safe := await Majacloud.cloud_save.save("progress", progress, loaded.value.revision)
if safe.error == "revision_mismatch":
pass # load again (details.current_revision), merge, save// Only overwrite the revision we loaded; another device may have saved since
const safe = await mc.cloudSave.save('progress', progress, { expectedRevision: loaded.value.revision });
if (!safe.ok && safe.error.code === 'revision_mismatch') {
// load again (safe.error.details.current_revision), merge, save
}curl -X PUT https://majacloud.majanite.com/v1/cloud/progress -H "X-Project-ID: $PROJECT_ID" -H "X-Client-Key: $CLIENT_KEY" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" -d '{"data": {"level": 4}, "revision": 3}'
# 409 revision_mismatch → details.current_revisionList and delete#
List the player's keys with their revisions and sizes, and delete keys you no longer need:
var keys = await Majacloud.CloudSave.ListAsync();
foreach (var entry in keys.Value) Debug.Log(entry.Key + " r" + entry.Revision + " " + entry.SizeBytes + " B");
await Majacloud.CloudSave.DeleteAsync("old_slot");var keys := await Majacloud.cloud_save.list_saves()
for entry in keys.value.keys:
print(entry.key, " r", entry.revision, " ", entry.size_bytes, " B")
await Majacloud.cloud_save.delete_save("old_slot")const keys = await mc.cloudSave.list();
for (const entry of keys.value.keys) console.log(entry.key, entry.revision, entry.size_bytes);
await mc.cloudSave.delete('old_slot');curl https://majacloud.majanite.com/v1/cloud -H "X-Project-ID: $PROJECT_ID" -H "X-Client-Key: $CLIENT_KEY" \
-H "Authorization: Bearer $TOKEN"
curl -X DELETE https://majacloud.majanite.com/v1/cloud/old_slot -H "X-Project-ID: $PROJECT_ID" -H "X-Client-Key: $CLIENT_KEY" \
-H "Authorization: Bearer $TOKEN"Limits#
- Up to 256 KB per document and 100 keys per player.
- Keys may contain letters, numbers, dots, dashes and underscores (up to 80 characters).
- Total storage per account depends on the plan (see Limits); above it saves fail with
plan_limitand nothing is deleted.