MrCode Posted December 4, 2023 Share Posted December 4, 2023 I need to save a table with some values to a player's account so I can then later on extract those values from the target account. For example: local values = getAccountData ( getPlayerAccount ( source ), "SavedTable" ) print: values[1] being "MrCode" or values[2] being "Deez Nutz 1234" The test function ( saveTableToAccount ) doesn't seem to save the table to the account at all, there are no errors either. So how do we save the table? function saveTableToAccount( source ) -- values what we want to save local playerName = getPlayerName ( source ) local playerInfo = "Deez Nutz 1234" -- set what we have as a table value in account data local tableToSave = { playerName, playerInfo } setAccountData( getPlayerAccount ( source ), "SavedTable", tableToSave ) -- what we saved outputChatBox( "saveTableToAccount - Player Name: (" .. playerName .. ") Infomation: (" .. playerInfo .. ")" ) end addCommandHandler( "save", saveTableToAccount ) -- Management / Utility -- To check what we've saved using 'saveTableToAccount' test function -- This function returns a table containing all the user data for the account provided function printAllData ( thePlayer ) local playerAccount = getPlayerAccount( thePlayer ) -- get his account if ( playerAccount ) then -- if we got the account then local data = getAllAccountData( playerAccount ) -- get data count = 0 for _ in pairs(data) do count = count + 1 end -- get the count outputChatBox ( "table holds " .. count .. " entries" ) -- output number of rows if ( data ) then for k,v in pairs ( data ) do outputChatBox(k..": "..v) -- print the key and value of each entry of data end end end end addCommandHandler( "getall", printAllData ) -- add a command handler for command 'getall' Link to comment
Spakye Posted December 4, 2023 Share Posted December 4, 2023 Hello, you need to use toJSON to turn the table into a string to be able to save it, and then use fromJSON to turn it back into a table when you need to use it. 1 1 Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now