File Manipulation


Jump to: navigation, search

The nice thing about emulating such a file manipulation library as Game Maker's is that the method of identifying a file is an integer, like everything else, which remains compliant with a 2-component variant data type. Though many may prefer to keep track of the FILE pointer themselves, this is a convenient method for those who don't wish to concern themselves with such.



Achieving a unified storage class between text, binary, and ini file manipulation is relatively simple due to the range of functions offered by the original Game Maker library. The binary file functions offered a method to clear the file and start anew; this requires reopening the file by its original name, which would need to be stored in that case. Text files likewise require a string to store the last line read. Neither category needs use of both.

That being the case, text and binary files are stored in a single structure containing a FILE* member and a string member.

Text File Functions


For efficiency concerns, a slight modification was made to text file behavior. While Game Maker does its reading in file_text_read_string/real, and just sets variables in file_text_readln and file_text_open, ENIGMA reads the first line in the file as soon as a call to open is made. This saves a check in calls to file_text_read_ string()/_real() down the road, but causes file_text_open_read() itself to take slightly longer. Typical use of these functions will introduce no visible difference, save minute speedup.

Binary File Functions

file_bin_open(fname,mode) opens the file fname as a binary file with the given mode, which is an integer from the table below.

Name Value Description
Read 0 Opens the file for reading.
Write 1 Opens the file for writing.
Both 2 Opens the file with read and write permissions.

C/C++ File Functions

Again, since EDL is extended upon C++, you still have access to the lower level file functions if you desire to access those. These include the C stdio functions, fopen, fread, fwrite, and fclose, in which case you would need to keep the FILE pointer, rather than just the variant integer.

Personal tools