/ Articles / Game Maker: Saving Progress

About This Blog

Yes, we are still very much alive!

This blog is a placeholder Gaming World's upcoming main site, GW6. The release date is still unknown even to us and this site is designed to introduce and keep you updated on what's happening in our community while the main site is being worked on.

Enjoy your stay at GW and register on the forums if you haven't done so already!

The Editors

ramirez (webmaster)

DragonSlayer (manager)

Sarevok

Raz

Wash Cycle

dicko

HL

crumply

Marcus

thecatamites

Murex Brandaris

Bakafura

PTizzle

Community | Games
Game Maker: Saving Progress
Game Maker: Saving Progress



Most games these days have a save feature so that the player can record his progress in case he wants to quit and play later. It may not become immediately apparent how to do this, so I have outlined three methods you can use to track progress in your games along with an example game showing how to do this in code.

Game Maker Internal Saving
Built into GM are two functions aptly named game_save("filename") game_load("filename"). Typically this is all most games will need to handle saving.


Game Maker has an option under Global Game Settings that will quicksave and quickload with F5 and F6. By default, it is enabled. Many people are unaware of this and I highly recommend you disable it unless you want this feature. While this may be good for testing, releasing a game with this feature may destroy the games challenge.

The major drawback to this is that if you release a new version of your game the save will probably not work as intended. Additionally, since it continues as if the player never quit, it can lead to some unexpected results if you were to have something like preferences. For instance: If you played the game with default settings, beat a few levels, quit, then you reloaded the game again and changed settings, upon reloading your old save it would revert to the old preferences. You can get things like this to work, but they require more leg work. I won't bother explaining this however, as if you have a game that has preferences and saving you will most likely want to do this manually so you won't have version problems.

PROS: Very easy to implement, saves every single value from the game so that it continues as if the player never quit.
CONS: Saves will only work well in the version it's saved under, meaning save files may not work across game updates. You also cannot manipulate the save file.

File Based Saving
The most flexible of any system, but also the hardest to implement. This involves you manually tracking all values that need to be saved (ie. items, level, character data) then writing it down to a file. You then load the file using the same order you saved in to assign the values you saved.


GM has functions for text, ini, and binary files.

While it is harder to implement, it allows you to do more than any other method. For instance, if you had a chapter based game, you could carry over save data from one chapter to the next by reading the file data of the old game. It also won't have version problems.

PROS: Can easily be manipulated, will never suffer compatibility issues.
CONS: Requires advanced knowledge. Need to track your values that are to be saved carefully.

Password Saving
I would not recommend a system that uses passwords that are random letters / numbers. The only reason passwords like this are even used is because in previous times some games had no means of saving data (PCs have hard drives), so used a password with data encoded into it to track progress. Kid Icarus is an example of human readable passwords, and is what you should do if you want to use this system.


Above are two password saving systems. Grid / image based systems are the same as password systems as they are simply translated into letters or numbers (as pointed out with the white text).

You can track variables and encode them into a password, but again, they would not be easy to remember and this would only be overly complicated when you can simply save the data to a text file.

PROS: Easy to do, allows players to easily access parts of the game.
CONS: Unless you make a complex password system, all passwords will do is send the player to a certain level. Not useful if you want to track any kind of values throughout the game.

Simple Platformer

A simple 5 level platformer that showcases three save methods.

This is a simple platformer with not many features. What's most important here is the showcase of the three password systems all talked about in this article. Download the game to find out how it's done.
Source + Executable

SCRIPT OF THE WEEK:

Script:sKey(keycode,clear);
Code:
Code:
1
2
3
4
5
6
//Syntax : Arg0 = Key to check ; Arg1 = If true, clear the key
if (keyboard_check(argument0)) {
if (argument1=1) keyboard_clear(argument0);
return (1);
}
return (0);
Example: sKey(vk_space,1);
Description: sKey is the exact same as keyboard_check, only specifying 1 after the keycode will reset the key. In the example above, it would check if spacebar is pressed, and if so, it would reset the key. Note that Windows will repeat the key after half a second at a pace set in the control panel. This behaviour is typically desirable however because if you think about something like a menu arrow, you want the first press to just move once, but if the key is held down for over half a second it will repeat the key until the key is released physically. If you handled all keystrokes through this script you have much greater control over the game as you can then execute events before or after any keystroke in the game that otherwise wouldn't be possible with keyboard_check. Even if you do not need any of this technical stuff, sKey is much quicker to type and will only save you time! To add this as a script, simply create a new script called sKey, then copy and paste the code into it.
Posted on June 22, 2008