fs_homepath directory for security.
Opening Files
fsOpen
Opens a file in the current game directory and returns a file handle.The name of the file to open (relative to the game directory)
The file access mode:
"read", "write", or "append"Returns a file handle (greater than 0) on success, or 0 on failure
Files must be closed after use with
fsClose() to prevent resource leaks.Reading Files
fsReadLine
Reads a single line from an opened file.The file handle returned by
fsOpen()Returns the line as a string (without the trailing
\n), or undefined if at the end of the file or an error occursExample: Reading all
Writing Files
fsWriteLine
Writes a line to an opened file. Automatically appends a newline character.The file handle returned by
fsOpen()The string data to write to the file
Returns
true on success, false on failureExample: Writing multiple
Managing Files
fsClose
Closes an opened file. Always call this when done with a file.The file handle to close
fsRemove
Deletes a file from the file system.The name of the file to delete
Returns
true if the file was deleted successfully, false otherwiseExample: Deleting old logs
testFile
Checks if a file exists in the file system.The name of the file to check
Returns
true if the file exists, false otherwiseExample: Checking before reading
Best Practices
Always Close Files
Use
fsClose() immediately after you’re done with a file to prevent resource leaks.Check File Handles
Always verify that
fsOpen() returned a valid handle before attempting to read or write.Use testFile
Check if a file exists before attempting to open it for reading.
Error Handling
Handle undefined returns from
fsReadLine() to detect end-of-file conditions.Complete Example
Example: Player statistics system