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:
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:
- iOS: On iOS, if you are loading an included file from a folder, ie: with a path something like "Backgrounds/background1.png", you do NOT need to include the folder as part of the path and simply supplying the file name is sufficient. On all other platforms you must supply the folder(s) as part of the path to the file.
- macOS and Ubuntu (Linux): On the macOS and Ubunutu, filenames and paths are case sensitive on these platforms, and so to prevent any potential issues, GameMaker Studio 2 will automatically make all names/paths use lower case by default.
- HTML5: On HTML5, saving and loading to and from local storage will work as explained within the different function pages, however if you are loading a file from a server, you must only use the function buffer_load_async() as loading synchronously has been deprecated on most browsers and will eventually be obsoleted.
The following sections all deal with different types of file handling:
Information on the different file functions can be found in the following pages:
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:
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).