Garry's Mod Wiki

net.ReadTable

  table net.ReadTable( boolean sequential = false )

Description

Reads a table from the received net message.

See net.WriteTable for extra info.

Sometimes when sending a table through the net library, the order of the keys may be switched. So be cautious when comparing (See example 1).

You may get net.ReadType: Couldn't read type X during the execution of the function, the problem is that you are sending objects that cannot be serialized/sent over the network.

You must read information in same order as you write it.

Arguments

1 boolean sequential = false
Set to true if the input table is sequential. This saves on bandwidth.

Returns

1 table
Table received via the net message, or a blank table if no table could be read.

Example

This is an example of how the keys order may be switched:

if ( CLIENT ) then local tbl = { Type = "Dining", Legs = "4", Material = "Wood" } net.Start( "TableSend" ) net.WriteTable( tbl ) net.SendToServer() PrintTable( tbl ) -- Prints the order client-side. end if ( SERVER ) then net.Receive( "TableSend", function( len, ply ) PrintTable( net.ReadTable() ) -- Prints the order server-side. end ) end
Output: Client:
Type = "Dining" Legs = 4 Material = "Wood"

Server:

Legs = 4 Material = "Wood" Type = "Dining"