• Player data with tables.
    3 replies, posted
Hi Facepunch users! Recently I try to set player data (setPData) with table. [code] ply.rantable={["SprintMeter"]={1,1,0},["DuckMeter"]={1,1,0},["WalkMeter"]={1,1,0},["JumpMeter"]={1,1,0}} ply:SetPData("Meters",ply.rantable) [/code] I try many ways. Print all values and tables. [code] ] lua_run for k,v in pairs(Entity(1):GetPData("TEST",{3,2,1})) do print(v) end > for k,v in pairs(Entity(1):GetPData("TEST",{3,2,1})) do print(v) end... [ERROR] lua_run:1: bad argument #1 to 'pairs' (table expected, got string) 1. pairs - [C]:-1 2. unknown - lua_run:1 [/code] If I print standart table all works! [code] ] lua_run for k,v in pairs(ply.rantable) do print(k) for i,m in pairs(v) do print(m) end end > for k,v in pairs(ply.rantable) do print(k) for i,m in pairs(v) do print(m) end end... SprintMeter 1 1 0 WalkMeter 1 1 0 DuckMeter 1 1 3 JumpMeter 1 1 0 [/code] How to save table in Data Base(no mysql)?
You can't store tables in SetPData. You can, however, store JSON strings and then convert it back to a table and loop through it.
[QUOTE=crazyscouter;45383836]You can't store tables in SetPData. You can, however, store JSON strings and then convert it back to a table and loop through it.[/QUOTE] How to use it?
Convert your table into a [URL="http://wiki.garrysmod.com/page/util/TableToJSON"]JSON[/URL] string. Store the string in the player data. Read the player data. Convert the string back to a [URL="http://wiki.garrysmod.com/page/util/JSONToTable"]table[/URL].
Sorry, you need to Log In to post a reply to this thread.