Wirebook

Wirebook › Lesson 12 of 18

How does a game remember where you got to?

About 6 minutes · hands-on · nothing you type leaves your browser unless a button says so

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.

The save-game machine

Walk the fox along the path and collect stars. Everything the game is doing right now lives in the tablet's working memory. Only the storage drawer keeps things when the power goes. Try switching off before and after you save. This game really is saved in your browser, so you can reload this page and the drawer is still full.

    Working memory (RAM)

    Super fast, but needs power every moment. Off means empty.

    Storage drawer (flash)

    Slower, but keeps things with the power off, for years.

    Cloud copy (someone else's computer)

    A copy on the game maker's server, when it's switched on.

    Press Walk to start your adventure.

    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!"

    So does it sleep in a little drawer? Yes, that's a good way to picture it. With the tablet fully off, your progress sleeps in the storage drawer as a save file. When the tablet is only asleep (screen off, but not shut down), RAM is kept powered with a trickle of electricity, so the game wakes up exactly where you left it, mid-jump. If the battery runs flat or the tablet needs memory for another app, the game gets closed, and then only the saved file is left.

    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.

    Why "Delete save data" really means it. Deleting a save removes the file from the drawer, and on modern tablets and phones it really can't be brought back (see where deleted files go). If there's a cloud copy, check whether that's deleted too before you press yes.

    Words from this lesson

    Earn your stamp

    Get all 3 right to collect the Saving games stamp. Wrong answers are fine: just try again.

    1. The tablet switches off before you save. Why is your newest progress gone?

    2. What does a save file usually contain?

    3. Why do careful games write a new save next to the old one instead of on top of it?

    Try another lesson

    1. 13How does a game know you really won?6 min · interactive
    2. 14How can lots of people play the same game together?7 min · interactive
    3. 15How does a website check your password without keeping it?8 min · interactive