• setmetatable() not working
    2 replies, posted
Hey, I'm at my wits end. setmetatable() is not working and I have no clue why. I've added two debug messages in the code, and I'll show the output after. Here is a function I made to setmetatable and output a function [CODE] function inv:New() local r = setmetatable({}, inv) print(r.AddSlot) print(inv.AddSlot) end [/CODE] Output in console when function is called: [CODE] nil function: 0x3bcc2be0 [/CODE] As you can see, for some reason r does not take the function AddSlot when metatable is set. I have done inv.__index = self I have no clue what is going wrong.
Where have you done inv.__index = self? And what is self? [code] local inv = {} inv.__index = inv function inv:AddSlot() end function inv:New() local r = setmetatable({}, inv) print(r.AddSlot) print(inv.AddSlot) end inv:New() [/code] Prints out the same function twice for me.
[QUOTE=bigdogmat;52016337]Where have you done inv.__index = self? And what is self? [code] local inv = {} inv.__index = inv function inv:AddSlot() end function inv:New() local r = setmetatable({}, inv) print(r.AddSlot) print(inv.AddSlot) end inv:New() [/code] Prints out the same function twice for me.[/QUOTE] That's it. I'm so stupid. I thought for some reason self applied when I assigned __index.
Sorry, you need to Log In to post a reply to this thread.