Sign in to follow this  
ma2med

[HELP] Tables

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?

Share this post


Link to post
Remove 4th line.

So Much?

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

Share this post


Link to post
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 
  

Share this post


Link to post

The backpack is not an element, you can't use destroyElement on it.

Anyway, that should be enough to delete the backpack:

Backpack.list[player] = nil 

Share this post


Link to post
The backpack is not an element, you can't use destroyElement on it.

Anyway, that should be enough to delete the backpack:

Backpack.list[player] = nil 

Okay, thank you very much

Share this post


Link to post

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.