A quick overview of verge file i/o functions. The standard procedure is to pass a filename to FileOpen() and get a file handle to use with the data read/write functions, and the close the file with FileClose() at the end. A few important points first. Opening a file in write mode will create a new file if one doesn't exist, but will overwrite if one does exist - just opening the file wipes all the data. Also, all read and write operations go from the current position in the file, which starts at the beginning, and move the position onwards in the process. Finally, the base unit of all everything here is the byte, 8 binary 1/0 switches, which equates to a number from 0 to 255 or one character of ascii text. There are two main uses for file i/o in verge, there's a brief summary of both below.
Reading from plain text data files
Useful for: Managing in-game data in an easy to access and alter form. Load-once purposes.
FileReadLn() to get a sting of data from the file
GetToken() to extract the information from the string
val() to turn string data into numbers where needed.
As it's easy to make the odd mistake when creating or editing datafiles by hand, be sure to add some error checking in case of mistakes, and preferably allow for extra non-data lines, so the file can be commented/explained where needed.
Writing and reading binary data files
Useful for: Recording and recalling data mid game. Fast read and write times.
FileWriteQuad() for writing any integer variables to file.
FileWriteString() for writing any string variables to file.
FileReadQuad() for reading integer variables from file.
FileReadString() for reading string variables from file.
There are several functions that do similar things, but these are relatively safe and simple, just remember to match the read and write formats exactly, and be aware changing either will cause big problems. For this reason, writing a 'version number' at the top of the file, and checking it is up to date on read might be useful.