Spielerando

Autosave

Autosave writes the player's progress by itself. It waits until the player has stopped changing things for a moment, but never longer than a set time, and only at a calm moment. Leaving the game saves at once, and a failed save is tried again after a wait that grows.

Also called: Auto-save, Background save, Automatic saving.

A plump patchwork tortoise sits on a stone in a quiet meadow while a ribbon of golden stitches flows from its open book into a floating purse that closes itself.
Thimblemoss Hollow, an invented cozy stitched adventure. Invented game, image generated with AI.

Paste this to your AI

Copy it into Claude, Cursor or ChatGPT. It already has good values and the usual mistakes in it.

Add "Autosave" to my game.

What it should do: Autosave means a crash, a dead battery or a closed window costs the player a minute of play and not an evening. The player never has to think about saving, and the game never freezes at a bad moment to do it.

Build it exactly as this state machine. First check that it fits my game, then build it like this:

```mermaid
stateDiagram-v2
  [*] --> clean
  clean: Nothing to save
  dirty: Changes waiting
  saving: Writing
  retrying: Waiting to retry
  clean --> dirty: player changes something
  clean --> saving: change while leaving
  dirty --> saving: calm and quiet or leaving
  saving --> clean: write worked
  saving --> dirty: worked, but more changed
  saving --> retrying: write failed
  retrying --> dirty: wait is over
  retrying --> saving: player leaves
```

Use these starting values:
- settleTime: 3 s
- maxUnsaved: 60 s
- retryDelay: 5 s
- writeTimeout: 10 s

Watch out for these common mistakes:
- The player never stops moving: Tell your AI: besides the quiet wait, add a longest wait. When it runs out, save anyway, at the next calm moment.
- Saving in the middle of a fight: Tell your AI: only start a save at a calm moment, which the game decides, for example on the ground with no enemy near. When leaving, save anyway, because it may be the last chance.
- Changes during the save: Tell your AI: take a copy of the data when the save starts, and remember if anything changed after that. When the write ends, only mark the data saved if nothing changed meanwhile.
- A failed save looks like a good one: Tell your AI: only count a save as done when the write reports success. Write to a new file first and swap it in when complete, so the old good save stays intact. Try again after a wait.
- A save that never answers: Tell your AI: give every save a time limit. When it runs out, treat the save as failed and try again later.
- Retrying every tick: Tell your AI: after a failure wait a few seconds, and wait longer after each failure in a row, up to a limit.
- Saving when nothing changed: Tell your AI: only save when something changed since the last good save.

Do not change anything else in the game. Do not claim anything without proof: model what it takes, and show me what your solution rests on and how I can see that it works. If you cannot show something, say you do not know. When you are done, tell me in plain words how to try it.

Or skip this and connect the MCP: your AI then finds all of this by itself.Connect the MCP

What it does

Autosave means a crash, a dead battery or a closed window costs the player a minute of play and not an evening. The player never has to think about saving, and the game never freezes at a bad moment to do it.

How it runs, as a diagram

Everything it can be in, and what moves it on. Your AI builds from exactly this.

player changes somethingchange while leavingcalm and quiet or leavingwrite workedworked, but more changedwrite failedwait is overplayer leavesNothing to saveChanges waitingWritingWaiting to retry
How it runs, as a diagram
  • Nothing to save → Changes waiting: player changes something
  • Nothing to save → Writing: change while leaving
  • Changes waiting → Writing: calm and quiet or leaving
  • Writing → Nothing to save: write worked
  • Writing → Changes waiting: worked, but more changed
  • Writing → Waiting to retry: write failed
  • Waiting to retry → Changes waiting: wait is over
  • Waiting to retry → Writing: player leaves

Good starting values

ValueStart withWhat it changes
settleTime3 sHow long the player must stop changing things before a save starts. Saving after every single change would write constantly while the player is busy. A few seconds of quiet is a good time to write.
maxUnsaved60 sThe longest a change may wait for a save once the moment is calm. A player who never stops moving would otherwise never be saved. This is also the most play a crash can cost.
retryDelay5 sHow long to wait after a failed save before trying again. The wait is multiplied by the number of failures in a row, up to six times, so a full disk is not hammered every moment. It is never zero.
writeTimeout10 sHow long a save may run without an answer. A save that hangs would block every later save, so after this time it counts as failed.

What usually goes wrong

The player never stops moving

If the game waits for a quiet moment and the player keeps changing things, the save never starts. A long session can then be lost at once.

Fix: Tell your AI: besides the quiet wait, add a longest wait. When it runs out, save anyway, at the next calm moment.

Saving in the middle of a fight

The save lands while the character is in the air, in a fight or on a loading screen. Loading it later puts the player in a moment that cannot be played, such as a fall that cannot be survived.

Fix: Tell your AI: only start a save at a calm moment, which the game decides, for example on the ground with no enemy near. When leaving, save anyway, because it may be the last chance.

Changes during the save

The player picks something up while the save is being written. If the game marks everything as saved when the write ends, that pickup is lost without any warning.

Fix: Tell your AI: take a copy of the data when the save starts, and remember if anything changed after that. When the write ends, only mark the data saved if nothing changed meanwhile.

A failed save looks like a good one

The disk is full or the write is cut off. The game thinks it saved and shows no warning, and the next time the player loads, an old or broken file is there.

Fix: Tell your AI: only count a save as done when the write reports success. Write to a new file first and swap it in when complete, so the old good save stays intact. Try again after a wait.

A save that never answers

The write hangs, for example because a cloud folder is offline. The game waits for the answer for ever and never starts another save.

Fix: Tell your AI: give every save a time limit. When it runs out, treat the save as failed and try again later.

Retrying every tick

A save fails and the game tries again at once, every tick. The game stutters and the disk is hammered, which often makes the failure worse.

Fix: Tell your AI: after a failure wait a few seconds, and wait longer after each failure in a row, up to a limit.

Saving when nothing changed

The game writes on a timer even when the player did nothing, for example while paused. This wears the disk and slows weak devices for no reason.

Fix: Tell your AI: only save when something changed since the last good save.

How to check it works

Works well with

Common questions

how do i add autosave to my game

Paste this: Add autosave. Mark the data as changed whenever the player changes something worth keeping. Save after 3 seconds without changes, or after 60 seconds at the latest, but only at a calm moment. Save at once when the player leaves. If a save fails, wait and try again.

how often should a game autosave

Not on a fixed timer. Save a few seconds after the player stops changing things, and no later than a minute after the first change. That keeps the loss small and the writes few.

why does my game freeze when it autosaves

The save runs on the same thread as the game and writes a big file. Take a copy of the data first, write it in the background, and start only at a calm moment. A short message such as a small icon tells the player it is happening.

what if the save file gets broken

Never write over the only good copy. Write a new file, check that it is complete, then swap it in. Keep the previous good file as a backup, so one cut-off write cannot destroy the whole save.

Where it comes from

We could not find a reliable origin for this one yet.

Where this mechanic comes from has not been researched yet.

Games are named only as references. Names and marks belong to their owners, and nothing here is endorsed by them.

What was checked

This is what separates the blueprint from a catalogue entry: the values on this page come from code that runs.

Your AI gets the code

Tested example code comes through the Spielerando connection, so your AI can use it right away. How to connect it