Garry's Mod Wiki

file.AsyncRead

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.

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. Arguments are:

  • string fileName - The fileName argument above.
  • string gamePath - The gamePath argument above.
  • number status - The status of the operation. The list can be found in Enums/FSASYNC.
  • 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

Special Pages


Wikis

?

Render Time: 76ms

DB GetPage 47
Generate Html 13
SaveChanges (1) 6
Render Body 0
Render Sidebar 7