File Handling


At some point while creating your game it will be necessary to store information externally and be able to retrieve this information. For example, you may wish to store login details, or hi-scores, or maybe the progression of the player through your levels. Whatever the reason, you will need to know how to use the different file functions that are available to you when working with GameMaker Studio 2.

It is very important to realise that GameMaker Studio 2 is Sandboxed, meaning that there are a number of limits and minor complications when using the file system functions that are available, and it is worth noting too that the file system will work slightly differently depending on the platform you are targeting. For more information this, please see the following section:

  1. The File System

If you have been granted permission by Steam to use their dedicated API with your game, you will find that there is also a new set of file functions available to you. These are explained in the Steam API section of this manual.

Finally, you should also note that there are some distinct differences between certain target platforms which whould be taken into account when using the file functions. These are:


The following sections all deal with different types of file handling:

Information on the different file functions can be found in the following pages:

  1. File System Functions
  2. Ini Files
  3. Text Files
  4. Binary Files

Obviously, there will be moments when you need to reference the directory in which files are store and GameMaker Studio 2 also has some special functions relating to the different possible directories that you may need:


When dealing with external files, there is always the possibility that the end user could open and change the information that they contain, and so change your game. This can result in broken game-play elements or fraudulent scores on-line (for example), and so GameMaker Studio 2 provides you with some basic encoding functions as well as functions to perform md5 checks on strings and files to make sure that they have maintained their integrity before being used. There are also two functions supplied for encoding and decoding JSON (JavaScript Object Notation) format strings.

NOTE: Encoding is NOT encryption! A base64 encoding renders the file unreadable to the naked eye and will require an effort on behalf of the user to decode, but it is not secure from hacking. It is recommended that you mix those functions with your own encryption (there are many forms of encryption and scripts are available on the internet).

IMPORTANT! All GameMaker Studio 2 projects have a file called "opions.ini", so you cannot name any file with that name (you will get a uid failure when you try to compile your game project).