Jump to content

Save items in the table


McDeKi

Recommended Posts

Hello, I was wondering how I should do save system for my inventory.

  
--//Zapis przedmiotow\\-- 
function zapiszEkwipunek() 
    for k,v in pairs( Plecak )do 
        for i=1, wysokoscY do 
          if not (Plecak[k][i] == false) then 
              outputChatBox(k.."|"..i.."|"..Plecak[k][i].id) 
            end 
        end 
    end 
end 
  

It works fine, output all items in inventory, for example here is the item with id 4, in the slot 5|1 and it outputs 5|1|4

What function I should use, split and gettok or table.insert and table.concat.

Link to comment
function zapiszEkwipunek() 
testing = {} 
    for k,v in pairs( Plecak )do 
        for i=1, wysokoscY do 
          if not (Plecak[k][i] == false) then 
              table.insert(testing, v) 
            end 
        end 
    end 
    return testing 
end 
  
-- and they save it like 
inventoryJson = toJSON(zapiszEkwipunek()) 
  
-- and get it from json 
inventoryTable = fromJSON(inventoryJson) 

Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...