Jump to content

Save items in the table


McDeKi

Recommended Posts

Posted

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.

Posted
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) 

Posted

I must save it according to scheme: Xslot, Yslot, ID for example (4,1,1|next Item|next Item) then I must save it in mysql as string and read the substrings, then I'm gonna add the items in the slots according to scheme X, Y, ID

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...