John Smith Posted September 24, 2016 Share Posted September 24, 2016 Hello. I am using this piece of code as a test example here: Mother = {}; Mother.__index = Mother; addEvent("onClientHandlerEvent"); function Mother:new() local self = setmetatable( {}, Mother ); self.type = "Mother"; triggerEvent("onClientHandlerEvent", localPlayer, self); return self; end function handlerTable(theTable) outputDebugString(tostring(theTable:getProperty("type"))); -- attempt to call method :getProperty (a nil value) end addEventHandler("onClientHandlerEvent", root, handlerTable); function Mother:getProperty(property) return self[property]; end local myMother = Mother:new(); outputChatBox(tostring(myMother:getProperty("type"))); -- works The issues that I'm having with this is that when I transfer the table with triggerEvent, function which handles that custom event cannot call any custom methods because apparently they're 'nil'. Why is this happening? Is this a triggerEvent issue? Link to comment
Gravestone Posted September 24, 2016 Share Posted September 24, 2016 I hope this works for you. function handlerTable(theTable) local theTable = Mother:new(); outputDebugString(tostring(theTable:getProperty("type"))); -- attempt to call method :getProperty (a nil value) end addEventHandler("onClientHandlerEvent", root, handlerTable); Link to comment
John Smith Posted September 24, 2016 Author Share Posted September 24, 2016 (edited) 24 minutes ago, Gravestone said: I hope this works for you. function handlerTable(theTable) local theTable = Mother:new(); outputDebugString(tostring(theTable:getProperty("type"))); -- attempt to call method :getProperty (a nil value) end addEventHandler("onClientHandlerEvent", root, handlerTable); You're using theTable as a function argument and then creating it below which is a leftover by the way, and the handler function is supposed to handle the table (aka recieve it), not create it. However thank you for trying to help me out, but this isn't what I'm looking for Edit: Well, this seems to be more an issue with triggerEvent, so you guys don't need to reply anything. Edited September 24, 2016 by John Smith Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now