Garry's Mod Wiki

Revision Difference

file.AsyncRead#544217

<function name="AsyncRead" parent="file" type="libraryfunc"> <description> Returns the content of a file asynchronously. All limitations of <page>file.Read</page> also apply. </description> <realm>Shared and Menu</realm> <added>2021.03.31</added> <args> <arg name="fileName" type="string">The name of the file.</arg> <arg name="gamePath" type="string">The path to look for the files and directories in. See <page text="this list">File_Search_Paths</page> for a list of valid paths.</arg> <arg name="callback" type="function"> A callback function that will be called when the file read operation finishes. Arguments are: * <page>string</page> fileName - The `fileName` argument above. * <page>string</page> gamePath - The `gamePath` argument above. * <page>number</page> status - The status of the operation. The list can be found in <page>Enums/FSASYNC</page>. * <page>string</page> data - The entirety of the data of the file. </arg> <arg name="sync" type="boolean" default="false">If `true` the file will be read synchronously.</arg> </args> <rets> <ret name="status" type="string"><page text="FSASYNC_OK">Enums/FSASYNC</page> on success, <page text="FSASYNC_ERR_">Enums/FSASYNC</page> on failure.</ret> <ret name="status" type="number"><page text="FSASYNC_OK">Enums/FSASYNC</page> on success, <page text="FSASYNC_ERR_">Enums/FSASYNC</page> on failure.</ret> </rets> </function> <example> <description>Prints the SteamIDs of players who will be automatically assigned to a user group when they connect to a server (Sandbox gamemode and derived).</description> <code> file.AsyncRead( "settings/users.txt", "GAME", function( fileName, gamePath, status, data ) if ( status == FSASYNC_OK ) then PrintTable( util.KeyValuesToTable( data ) ) end end) </code> <output> ``` admin: garry = STEAM_0:1:7099 superadmin: garry = STEAM_0:1:7099 ``` </output> </example>