How to make save/loads?

Saving and restoring has a problem: if you upgrade the game, it can break all existing saved games. The most obvious way this can happen is if you *create a new stat, which gets set in the first chapter. Anyone restoring their games in subsequent chapter won’t have that stat set.

It’s easy to write code that improperly assumes that a certain stat is set to a valid value, e.g. *if/*else chains that consider only three possibilities, but don’t consider the fourth possibility that the variable is unset. These *if/*else chains contain a bug that only happens when upgrading an old saved game; there’s no way to find those bugs through ordinary play. Quicktest and Randomtest will be useless for finding bugs like this; they only test the game as it is, not as the game used to be / could have been.

There are a bunch of subtle ways that saved games can be invalidated. Maybe someone saves a game in the maze.txt chapter, but in the current latest version, there are new restrictions to access that chapter (maybe you had to befriend a minotaur before you can enter the maze). During the maze, your minotaur friend is supposed to say a few lines of dialogue, but you don’t have a minotaur friend, because you restored a save from the old version, where you could enter the maze without one.

This is why Choice of the Vampire recently threw out all of its existing saved games when Volume 4 was released. The old saved games were severely invalid. Too much had changed in the earlier volumes.

If you’re very very careful with upgrades, you can find and fix all of these bugs, but we felt that offering CS authors an unrestricted save/restore mechanism was like handing authors a gun to shoot themselves in the foot.

12 Likes