GameMaker Studio · GML · Cloud saves
gmda_saveGame
Writes (upserts) a cloud save slot with a free-form data struct.
Signature
gmda_saveGame(slot, data_struct)What it does
POSTs /saves (upsert on game+player+slot), so it is safe to retry and saving to a used slot overwrites it. On success the queued save_completed event carries response = { success: true, save: { slot, size_bytes, updated_at } }. On a validation, slot-limit, storage, or plan failure the event carries success=false and an error string (e.g. "Save data validation failed: ...", "Slot 5 exceeds maximum allowed (3)", "Cloud saving is not configured for this game"). Returns 0 immediately (no event) when there is no active session or slot is out of 1..10.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| slot | real | required | Save slot, 1 to 10. |
| data_struct | struct | required | Your save object, sent as JSON. It must match the save schema you define in the panel; the server validates it field by field and rejects unknown keys. The submit route accepts up to 10MB. |
How to call it
Fire gmda_saveGame(), then drain the queue with gmda_pollEvent() in a Step event and react when e.event == "save_completed".
Result event: save_completed { success, response }
Example
gmda_saveGame(1, { level: 5, coins: 120, unlocked: ["sword"] });
// later, in a Step event:
var e = gmda_pollEvent();
while (!is_undefined(e)) {
if (e.event == "save_completed") {
if (e.success) show_debug_message("Saved slot " + string(e.response.save.slot)
+ " (" + string(e.response.save.size_bytes) + " bytes)");
else show_debug_message("Save failed: " + string(e.error));
}
e = gmda_pollEvent();
}Use cases
- Persist player progress to the cloud.
- Sync a player's game across devices.