I have this as my saving function:
[lua]
function SaveData()
local PlayerData = { }
PlayerData[ "money" ] = ply:GetNWInt( "playermoney" )
file.Write( "ShittyScript/" .. ply:UniqueID() .. ".txt", util.TableToKeyValues( PlayerData ) )
end
[/lua]
Which seems to do nothing and doesen't save anything to my server's data folder when it's called on the disconnect hook.
Then the loading function:
[lua]
function LoadData()
if( file.Exists( "ShittyScript/PlayerDataStore/" .. ply:UniqueID() .. ".txt" ) ) then
local tbl = util.KeyValuesToTable( file.Read ( "ShittyScript/" .. ply:UniqueID() .. ".txt" ) )
local PlayerData = util.KeyValuesToTable( file.Read( "ShittyScript/" .. ply:UniqueID() .. ".txt" ) )
for k, v in pairs( tbl ) do
ply:SetNWInt( k, v )
end
ply:SetNWInt( "playermoney", PlayerData[ "playermoney" ] )
end
end
[/lua]
Which also seems to not work, any clue on how to fix this?
yes, first, on both fonctions you are not actually putting the ply Variable in. Fix that and retry.
In addition to not actually passing the ply object to the function, you shouldn't use util.TableToKeyValues and util.KeyValuesToTable, as they're deprecated. Instead, use the GLON functions: [url]http://wiki.garrysmod.com/?title=Glon[/url]
-snip-
[QUOTE=Skyhawk;18010591]In addition to not actually passing the ply object to the function, you shouldn't use util.TableToKeyValues and util.KeyValuesToTable, as they're deprecated. Instead, use the GLON functions: [url]http://wiki.garrysmod.com/?title=Glon[/url][/QUOTE]
You earned a box for that. Don't believe everything people put on the wiki, its not true-- even idiots can edit pages.
glon in no way depreciated util.TableToKeyValues and util.KeyValuesToTable.
For something simple like this, its 100% acceptable and far easier for him to use.
[QUOTE=foszor;18078791]You earned a box for that. Don't believe everything people put on the wiki, its not true-- even idiots can edit pages.
glon in no way depreciated util.TableToKeyValues and util.KeyValuesToTable.
For something simple like this, its 100% acceptable and far easier for him to use.[/QUOTE]
Sure, it'll be fine for the development period, and possibly a while after that. The major bugs of the KeyValues system have a nasty tendency to only show up after release - such as the fact that you can't use quotes in strings, unless you want it to be unloadable. This really bit me in the ass when I first used KeyValues to save player data and didn't find it until someone with a quote in their name joined.
There are numerous bugs with KeyValues, and the [url=http://www.facepunch.com/showthread.php?t=814313] occurrences are not always consistent[/url].
Sure it is easy to use util.TableToKeyValues and util.KeyValuesToTable, it is also easy to use glon.encode and glon.decode, or Json.Encode and Json.Decode. The effort on the developer's behalf is practically the same - yet the result is so much better.
[b]Edit:[/b] Though I do agree with you they that they are not depreciated. Instead, they are more of superseded.
[QUOTE=Deco Da Man;18079028]Sure, it'll be fine for the development period, and possibly a while after that. The major bugs of the KeyValues system have a nasty tendency to only show up after release - such as the fact that you can't use quotes in strings, unless you want it to be unloadable. This really bit me in the ass when I first used KeyValues to save player data and didn't find it until someone with a quote in their name joined.
There are numerous bugs with KeyValues, and the [url=http://www.facepunch.com/showthread.php?t=814313] occurrences are not always consistent[/url].
Sure it is easy to use util.TableToKeyValues and util.KeyValuesToTable, it is also easy to use glon.encode and glon.decode, or Json.Encode and Json.Decode. The effort on the developer's behalf is practically the same - yet the result is so much better.
[b]Edit:[/b] Though I do agree with you they that they are not depreciated. Instead, they are more of superseded.[/QUOTE]
People were successfully saving data way before glon came along-- I have backups from our old server data where we tracked over 20k players for more than 2 years. I never ran into any problems, even with strings.
Glon didn't do anyone any favors.
It did remove the need to table.Sanitise and table.DeSanitise in addition to those keyvalue functions, though.
Why fight over glon or util.Key shit. There are 2 choices now, let people choose and stfu.
[QUOTE=Chewgum.;18084364]Why fight over glon or util.Key shit. There are 2 choices now, let people choose and stfu.[/QUOTE]
Thanks for such an intelligent insight on this topic of discussion.
Thanks for helping me..
But really, I've used Glon instead, ty.
Sorry, you need to Log In to post a reply to this thread.