Jump to content

[HELP] Tables


ma2med

Recommended Posts

In your code is a function of creating a backpack

addEventHandler('onPlayerJoin', root, 
    function () 
        Backpack:create(source) 
    end 
) 

But do not have delete function backpack

addEventHandler('onPlayerQuit', root, 
    function () 
        --Backpack Delete 
    end 
) 

Help with function delete backpack

Example

  
function BackPack:delete(player) 
    Backpack.list[player] = nil 
    setmetatable(self, self) 
    return true 
end 
  

I did the right function?

Link to comment
Yes, that's right, Monson.

See if the backpack is created so

  
function Backpack:create(player, slots) 
    if (Backpack.list[player]) then 
        return Backpack.list[player] 
    end 
    local new = { 
        items = {}, 
        slots = slots or 100, 
        owner = player 
    } 
    setmetatable(new, {__index = Backpack}) 
    Backpack.list[player] = new 
    return new 
end 
  

And thus is deleted

  
function Backpack:delete(player) 
    Backpack.list[player] = nil 
    return true 
end 
  

Maybe I should null and

  
self.items = nil 
self.slots = nil 
self.owner = nil 
--or 
destroyElement(self.items) 
destroyElement(self.slots) 
destroyElement(self.owner) 
--or 
destroyElement(self) 
  

And thus should delete the backpack?

  
function Backpack:delete(player) 
    self = nil 
--or 
    destroyElement(self) 
    Backpack.list[player] = nil 
    return true 
end 
  

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