Garry's Mod Wiki

file.AsyncRead

  number file.AsyncRead( string fileName, string gamePath, function callback, boolean sync = false )

Description

Returns the content of a file asynchronously.

All limitations of file.Read also apply.

This function is currently broken in the Menu State and won't be fixed. Bug Report

Arguments

1 string fileName
The name of the file.
2 string gamePath
The path to look for the files and directories in. See this list for a list of valid paths.
3 function callback
A callback function that will be called when the file read operation finishes.
Function argument(s):
1 string fileName - The fileName argument above.
2 string gamePath - The gamePath argument above.
3 number status - The status of the operation. The list can be found in FSASYNC enum.
4 string data - The entirety of the data of the file.
4 boolean sync = false
If true the file will be read synchronously.

Returns

1 number status
FSASYNC_OK on success, FSASYNC_ERR_ on failure.

Example

Prints the SteamIDs of players who will be automatically assigned to a user group when they connect to a server (Sandbox gamemode and derived).

file.AsyncRead( "settings/users.txt", "GAME", function( fileName, gamePath, status, data ) if ( status == FSASYNC_OK ) then PrintTable( util.KeyValuesToTable( data ) ) end end)
Output:
admin: garry = STEAM_0:1:7099 superadmin: garry = STEAM_0:1:7099