File Handling

This section deals with the different types of functions available for 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.

It is very important to realise that GameMaker: Studio 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. File System Limits

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.

File Systems

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

Directories

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

  1. directory_exists
  2. directory_create
  3. directory_destroy
  4. temp_directory
  5. working_directory
  6. program_directory

Encoding

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 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.

  1. base64_encode
  2. base64_decode
  3. json_encode
  4. json_decode
  5. md5_string_utf8
  6. md5_string_unicode
  7. md5_file
  8. sha1_string_utf8
  9. sha1_string_unicode
  10. sha1_file

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).

Zip Files

GameMaker: Studio permits you to open a zip file and extract its contents to the local storage area for your game, using the following functions (useful should you have downloadable content for your game):

  1. zip_unzip


Back: Reference
© Copyright YoYo Games Ltd. 2018 All Rights Reserved