• net.WriteTable() Scrweing Up Table Keys
    8 replies, posted
Hello, I have a table defined on the server and am using net.WriteTable() to transfer it to the client Using PrintTable() on the client and server result in different key values. These are integer keys. What is the meaning of this? A bug in the net library? Server Output: [code]1229174912: Nick = [sYƨ]» ÐR. Lúå Group = User ID = 1[/code] Client Output: [code]1229174882: Group = User ID = 1 Nick = [sYƨ]» ÐR. Lúå[/code] Client Receive: [code]net.Receive( "KKB_CustomUsers_Reload", function(len) table.Empty(KKB.CustomUsers) KKB.CustomUsers = net.ReadTable() PrintTable(KKB.CustomUsers) if ( KKB.CustomUsersList != nil ) then KKB.Custom_Users_Reload_CustomUsers() end end )[/code] Server Send: [code]util.AddNetworkString( "KKB_CustomUsers_Add" ) net.Receive( "KKB_CustomUsers_Add", function(len, ply) local Group = net.ReadString() local ID = tonumber(net.ReadUInt( 32 )) local Ply = player.GetByID( ID ) local UniqueID = tonumber(Ply:UniqueID()) if ( KKB.CustomUsers[UniqueID] == nil ) then local CurrentGroup = Ply:GetUserGroup() if ( CurrentGroup != Group ) then KKB.CustomUsers[UniqueID] = {} KKB.CustomUsers[UniqueID].ID = ID KKB.CustomUsers[UniqueID].Nick = Ply:Nick() KKB.CustomUsers[UniqueID].Group = Group KKB.Send_CustomUsers( nil ) PrintTable(KKB.CustomUsers) end end end)[/code] [code]util.AddNetworkString( "KKB_CustomUsers_Reload" ) function KKB.Send_CustomUsers( Ply ) net.Start( "KKB_CustomUsers_Reload" ) net.WriteTable( KKB.CustomUsers ) if ( IsValid(Ply) ) then net.Send( Ply ) else net.Broadcast() end end[/code]
It's only the print order. Do this serverside and clientside. [code]print(tbl[ 1 ], tbl[ 2 ], tbl[ 3 ])[/code] And you'll see that the result will be same on both sides.
The table KEY has changed. 1229174912 on the server to 1229174882 after sending to the client I've fixed this by setting the table key as a string, which is what UniqueID outputs. Nonetheless something fudged up hardcore with net.WriteTable and/or net.ReadTable for it to mess the table key up.
[QUOTE=kklouzal23;41644423]I've fixed this by setting the table key as a string, which is what UniqueID outputs. Nonetheless something fudged up hardcore with net.WriteTable and/or net.ReadTable for it to mess the table key up.[/QUOTE] I want to make sure I understand this right, so you're saying table A sends fine but table B gets messed up? The only difference being whether the key 1229174912 is a string or a number? If table A was: [lua]{ ["1229174912"] = { Nick = '[sYƨ]» ÐR. Lúå', Group = 'User', ID = 1 } }[/lua] and table B was: [lua]{ [1229174912] = { Nick = '[sYƨ]» ÐR. Lúå', Group = 'User', ID = 1 } }[/lua]
There is only 1 table, built on the servers end. This table is printed to console. Table is then sent to client. Client prints table contents. Table keys mismatch. Changing keys from integer to string fixed. Although integer keys should have worked.
Probably because Garry made them send it as a float because it's a number. Instead of using net.WriteTable, try just sending the values individually and then rebuild the table on the client, that way you don't have to send keys like "Nick", "Group" and "ID" which would marginally increase the amount of data you have to send. And use net.WriteUInt() for sending the large values.
What's odd is that you are attaching the table to uniqueID instead of player entity. Wouldn't it be just easier to do. [code]ply.MyTbl = {}[/code] instead of [code]TblOfPlayers['UniqueID'] = {}[/code] Or if you want to keep everything in one table [code]TblOfPlayers[ply] = {}[/code]
[QUOTE=Netheous;41646726]What's odd is that you are attaching the table to uniqueID instead of player entity. Wouldn't it be just easier to do. [code]ply.MyTbl = {}[/code] instead of [code]TblOfPlayers['UniqueID'] = {}[/code] Or if you want to keep everything in one table [code]TblOfPlayers[ply] = {}[/code][/QUOTE] Probably for persistent storage.
It's for my prop protection to allow dual usergroups, this holds the list of players that have a custom usergroup in the PP from that of ULIB. So I need to store by UniqueID so I can call player.GetByUniqueID Otherwise I can store by SteamID and keep a list of connected players in a table, the keys would be SteamID's and the value would be their player entity.
Sorry, you need to Log In to post a reply to this thread.