Chapter 8, part 1

A less prominent but very important part of game making is finding a way to store data when the program ends.

Anyone who has played games before has seen the ability to store data and recall it later. This data is not lost when the program quits, and can be read by the program at a later time to recall some prior operating state. In games, the most common things to store are lives, health, level, and equipment. This section will detail not only how to receive and interpret data and how to save it to a secure location, but also what types of variables on the calculator are best for retaining the data.

Let's first discuss places where the data can be saved. There are two basic types of variables that can be used—temporary variables and long-term variables, distinguished by their volatility when used to retain data over a long period of time.

The real variables are the most easily accessible and the most used places to hold data. This makes them bad for long-term storage, as any other program that is run is likely to alter its data. The real variables are great for holding data temporarily while a program performs some execution, but should not be relied upon outside the program. We need a more stable storage location.

The system variables are the next option. While they are not used as often as real variables, they are more unstable. For example, any data placed in the variable Xmin will be altered any time the graph screen's range is changed.

GDB and picture hold data about the graph settings or drawings on the graph screen, respectively. But for numerical data, they are still no help.

Lists present a worthwhile solution and have a very low volatility. A list can be created by a program and given a five-character name to help identify it. The program can then destroy lists once they are no longer needed, or kept in memory if data needs to be retained. Plus, having a unique name ensures that the list should not be altered by another program or function. Lists can be as large as memory permits. They may also be moved to and from the archive in order to protect program data.

+ Tweet