Default and Define

There are two main ways to declare variables: default and define. Which you should use depends on how you intend to use the variable. Both kinds have global scope: they are available to use in any file of your game.

Default - for variables

Use default for true variables that will change during the course of game play. A variable declared with default will always be written to the save game.


default gameOver    = False     # Has the game finished?
default pcHp        = 10        # Player health 0..pcHpMax   
default pcMoney     = 100       # Player cash

When a game is loaded the values from the save game will be used. If later version of the game adds a new default value, that will be used when it's not present in an older save.

Define - for constants

Use define for things that are really constants that will only change between releases of your game. A variable declared with define will not be written to the save game.


define pcHpMax     = 10        # Player maximum health   
define swordCost   = 250       # Cost of a good sword

When a game is loaded it won't contain values for your "variables" declared with define so the values established at init-time will remain intact. So if a later version of your game has a different value for swordCost that value will apply to an old save loaded into the new version.

And the other way...

There's a third way to create a variable, using one or more lines of Python, which should be avoided if possible:


label start:
    $ pcHeightIn = 72           # Player height in inches

The problem with this is that it doesn't indicate whether the variable should or should not be included in the save game. It also won't exist until that line of code is run; here after the Start button is pressed. If you add new variables in this way to a new version of the game they won't exist until the player starts a new game.

Getting organised

It can be helpful to keep the declarations of the different kinds of variables in separate files for ease of reference. Earlier I suggested keeping all your characters (declared with define) in one file such as characters.rpy. You may want to put other constants (declared with define) in a file such as const.rpy, and your real variables (declared with default) in a file such as vars.rpy.

Inspecting save games

To check what has and what hasn't been saved you can always use a save game editor tool.