Wirebook › Lesson 12 of 18
How does a game remember where you got to?
You're halfway through a level, the tablet goes off, and the next day the game puts you right back where you were. So where was your progress all night? Was it sleeping in a little drawer inside the tablet? Pretty much, yes. Here's a pretend tablet so you can play, save, switch it off, and even pull the battery out halfway through a save to see what survives.
Two kinds of memory
A tablet, phone or games console has two very different places to keep things. Working memory, called RAM, is where a game keeps everything it's using right now: where your character is standing, how many lives you have, which enemies are chasing you. RAM is incredibly fast, so the game can change those numbers many times a second. But RAM holds information as tiny electric charges that leak away in a fraction of a second, so it has to be topped up constantly. Cut the power and it's blank.
Storage is the drawer. In tablets and phones it's flash memory, the same kind as in a memory stick. Flash traps electric charges inside little insulated boxes, so they stay put with no power for years. It's much slower than RAM, which is why games don't do all their thinking there.
What "saving" really does
When you save, the game copies a short description of your progress out of RAM and writes it into a save file in storage. It doesn't save the whole picture on the screen, only the facts it needs to rebuild it: level 3, standing at the 7th square, 5 stars, the blue door already open. That's why a save file is often tiny, sometimes just a few hundred letters and numbers, like the ones you can read in the drawer above.
When you press Continue, the game reads that file back into RAM and draws the world again from those facts. Anything you did after the last save was only in RAM, so it's gone. That's the moment you groan "I didn't save!"
Autosave, checkpoints and the battery problem
Many games save by themselves at checkpoints, like the flags in the game above, so you don't have to remember. Writing to storage takes a moment, though. If the power goes in the middle of writing, the save file can be left half-new, half-old: scrambled. Try it above with safe saving off.
Careful games use a trick: they write the new save as a separate file next to the old one, check it, and only then swap the label over to the new one. If the power dies halfway, the old save is still there, untouched. Many also add a checksum, a small number worked out from the whole save. When loading, the game works it out again; if the two numbers don't match, it knows the file is broken and uses the older one instead. That's why some games say "Do not turn off the power while this icon is showing".
Cloud saves
Storage can be lost too: a tablet gets dropped, lost or replaced. Cloud saves send a copy of your save file to the game maker's servers over the internet. Sign in on a new device and the game downloads your progress. It's just a copy kept on someone else's computer, so it only exists if the game supports it and the copy got uploaded before the old tablet went for a swim.