›Cloud saves

Cloud saves with CudicSave

Progress that survives a refresh is the difference between a toy and a game. Cudic games get it with one script tag: saves bind to the player's account, so their progress follows them across sessions and devices — and every Cudic player already has it, no keys, no backend work for you.

Cudic Cookbook · pairs with Clicker mechanics

How it works (10 seconds)

Your game runs in a sandboxed frame and never holds a login token — a bad actor can't steal sessions that way. Instead, the game asks Cudic's host page (the game's view page, or Studio's preview while you're building) to do the storing, with your player's account attached server-side. You talk to a tiny object called CudicSave:

<script src="/cudic-save.js"></script>
<script>
  CudicSave.load().then(function (data) { … });  // data or null — your previous JSON
  CudicSave.save({ best: 12, coins: 34 });        // debounced cloud write, 1.5 s
  CudicSave.clear();                              // wipes local + cloud copy
</script>

The pattern in a real game

Load before first paint, merge, render; save whenever something meaningful changes.

<script src="/cudic-save.js"></script>
<script>
  var best = 0, coins = 0;

  CudicSave.load().then(function (data) {
    if (data && typeof data === 'object') {
      best  = typeof data.best  === 'number' ? data.best  : 0;
      coins = typeof data.coins === 'number' ? data.coins : 0;
    }
    render();   // only trust shapes you defined — always coalesce, never assign raw
  });

  function gameOver(finalScore) {
    if (finalScore > best) { best = finalScore; CudicSave.save({ best: best, coins: coins }); }
  }
</script>

Validate on load. Old saves from old builds live in the same slot forever — if version 2 changed what best means, version 1 tables still return it. typeof checks cost nothing and prevent "NaN highscore" bugs.

What each method promises

CallBehaviour
load()Resolves with your saved object, or null for a player the platform hasn't seen before. It resolves even offline (from the local mirror).
save(obj)Writes locally right away, then to the player's account 1.5 seconds later if no newer changes arrive — rapid-fire saves don't spam the network.
clear()Reset for the current game: clears the local mirror and the cloud copy for this game only.

Guests, sign-ins and the 100 KB budget

  • Guests persist nothing. A signed-out player's saves are memory-only for the session; the game nudge to sign in comes from Cudic itself (view shows it once), so you write zero code for it.
  • 100 KB per game per account. JSON numbers and short strings go a very long way — compress coordinates into compact objects early rather than "saving everything just in case".
  • While building, Studio's preview uses its own local test slot keyed to your project — building and playtesting never overwrites a real player's progress, and signing out doesn't block testing.

One habit worth adopting: save on gameOver, on unlock milestones, and beforeunload-ish "session totals" — not on every frame. The debounce protects you from thrash, but only-worthy saves in the first place make a cleanly resumable game.

Once your clicker or platformer keeps score across reloads, publish it — then watch a friend's play session in the gallery feel like theirs, not a demo.