Registry

Game Maker 8

Registry

If you want to store a small amount of information between runs of the game there is a simpler mechanism than using a file. You can use the registry. The registry is a large database that Windows maintains to keep track of all sorts of settings for programs. An entry has a name, and a value. You can use both string and real values. The following functions exist:

registry_write_string(name,str) Creates an entry in the registry with the given name and string value.
registry_write_real(name,x) Creates an entry in the registry with the given name and real value.
registry_read_string(name) Returns the string that the given name holds. (The name must exist. Otherwise an empty string is returned.)
registry_read_real(name) Returns the real value that the given name holds. (The name must exist. Otherwise the number 0 is returned.)
registry_exists(name) Returns whether the given name exists.

Actually, values in the registry are grouped into keys. The above routines all work on values within the key that is especially created for your game. Your program can use this to obtain certain information about the system the game is running on. You can also read values in other keys. You can write them also but be very careful. YOU CAN EASILY DESTROY YOUR SYSTEM this way. (Write is not allowed in secure mode.) Note that keys are again placed in groups. The following routines default work on the group HKEY_CURRENT_USER. But you can change the root group. So, for example, if you want to find out the current temp dir, use

  path = registry_read_string_ext('\Environment','TEMP');

The following functions exist:

registry_write_string_ext(key,name,str) Creates an entry in the key in the registry with the given name and string value.
registry_write_real_ext(key,name,x) Creates an entry in the key in the registry with the given name and real value.
registry_read_string_ext(key,name) Returns the string that the given name in the indicated key holds. (The name must exist. Otherwise an empty string is returned.)
registry_read_real_ext(key,name) Returns the real value that the given name in the indicated key holds. (The name must exist. Otherwise the number 0 is returned.)
registry_exists_ext(key,name) Returns whether the given name exists in the given key.
registry_set_root(root) Sets the root for the other routines. Use the following values:
0 = HKEY_CURRENT_USER
1 = HKEY_LOCAL_MACHINE
2 = HKEY_CLASSES_ROOT
3 = HKEY_USERS