File Functions⚓︎
Warning
The MWSE-mwscript API is deprecated. The documentation found here is for legacy purposes only. None of the following functions can be used directly from Lua.
xFileReadFloat⚓︎
Parameters:
stringfilename: The file to read values from.longcount: The number of values desired.
Returned:
longvaluesRead: The number of results actually read. This may differ from count if it encountered an error while reading.floatvalue: A value read. A number of values are returned equal to valuesRead.
Reads a number of float (4 byte) values requested from filename at the current reading position. The current position is then advanced. Returns the number of values actually read (valuesRead) followed by the values.
xFileReadLong⚓︎
Parameters:
stringfilename: The file to read values from.longcount: The number of values desired.
Returned:
longvaluesRead: The number of results actually read. This may differ from count if it encountered an error while reading.longvalue: A value read. A number of values are returned equal to valuesRead.
Reads a number of long (4 byte) values requested from filename at the current reading position. The current position is then advanced. Returns the number of values actually read (valuesRead) followed by the values.
xFileReadShort⚓︎
Parameters:
stringfilename: The file to read values from.longcount: The number of values desired.
Returned:
longvaluesRead: The number of results actually read. This may differ from count if it encountered an error while reading.shortvalue: A value read. A number of values are returned equal to valuesRead.
Reads a number of short (2 byte) values requested from filename at the current reading position. The current position is then advanced. Returns the number of values actually read (valuesRead) followed by the values.
xFileReadString⚓︎
Parameters:
stringfilename: The file to read values from.
Returned:
stringvalue: The value read from the file.
Reads from filename at the current reading position, until a C-style null terminator (\0/0x00) is read. The current position is advanced as read, and the resultant bytes are returned as a string.
xFileReadText⚓︎
Parameters:
stringfilename: The file to read values from.stringpattern: The pattern to match when reading.
Returned:
longnumMatches: The number of values read.variesmatches: A value returned. A number of values will be returned matching numMatches.
xFileReadText reads a text string from from the file at the current reading position. The current position is then advanced. The pattern string is then used to extract data from the string just read; the first return value indicates how much of the pattern is matched. The values matched by the pattern are also returned.
The pattern and return values are the same as for the xStringParse function with one addition: placing a single % sign at the end of the pattern will cause the read routine to stop when it gets to the end of a line (CR/LF) allowing you to use this to read a normal text file instead of a binary file. Without the trailing % sign on the pattern this will read up to the first NULL character or to the end of the file if it doesn't find a NULL character.
xFileRewind⚓︎
Parameters:
stringfilename: The file to rewind.
Returned:
- None
This function moves the current reading position to the start of the file.
Call this or xFileSeek at the start of any script which uses file reading or writing functions, otherwise you will have problems with the current file position not being as expected.
xFileSeek⚓︎
Parameters:
stringfilename: The file to seek in.longposition:
Returned:
- None
This function moves the current reading position to the specified offset in the file.
You should call this or xFileRewind every frame before using other file functions. Use an offset divisible by 2 to read shorts and an offset divisible by 4 to read longs.
This function isn't very useful if the file contains string data.
xFileWriteFloat⚓︎
Parameters:
stringfilename: The file to write value to.floatvalue: The value to write to file.
Returned:
- None
Writes a float (4 byte) value to filename at the current position. The current position is then advanced.
Note
The file is truncated at the current position (just after the end of the new value). This means that you cannot use this to modify the values in the middle of an existing file.
xFileWriteLong⚓︎
Parameters:
stringfilename: The file to write value to.longvalue: The value to write to file.
Returned:
- None
Writes a long (4 byte) value to filename at the current position. The current position is then advanced.
Note
The file is truncated at the current position (just after the end of the new value). This means that you cannot use this to modify the values in the middle of an existing file.
xFileWriteShort⚓︎
Parameters:
stringfilename: The file to write value to.shortvalue: The value to write to file.
Returned:
- None
Writes a short (2 byte) value to filename at the current position. The current position is then advanced.
Note
The file is truncated at the current position (just after the end of the new value). This means that you cannot use this to modify the values in the middle of an existing file.
xFileWriteString⚓︎
Parameters:
stringfilename: The file to write value to.stringvalue: The value to write to file.
Returned:
- None
Writes a string value to filename at the current position. The string is stored in the file as a C-style null-terminated string. The current position is then advanced.
Note
The file is truncated at the current position (just after the end of the new value). This means that you cannot use this to modify the values in the middle of an existing file.
xFileWriteText⚓︎
Parameters:
stringfilename: The file to write value to.stringformat: The format to use when writing to the file.variesvalues: Multiple values that match the format.
Returned:
- None
Writes a formatted string to the file at the current position and advances.
The formatting rules are the same as for the xStringBuild function with one addition. Placing a % at the end of the pattern will suppress the NULL that is normally printed, so a format string ending with %N% can be used to create a normal text file.
Note
The file is truncated at the current position (just after the end of the new value). This means that you cannot use this to modify the values in the middle of an existing file.