I have a question about getting access to class data from within an event listener function...
I have successfully set up an event listener function inside my class and am passing extra event data through to it without problems.
However in addition to the data I am passing through to the listener function, I would also like to access data from the class itself using the self. qualifier however I get the common error 'attempt to index field 'xxx' (a nil value).
Am I wrong to assume that inside an event listener function I would have access to class properties? Do I only have access to event data specifically passed to the listener function?
I can provide a code sample if the above explanation is confusing
Thanks
Comments
Author of Learn Lua for iOS Game Development from Apress ( http://www.apress.com/9781430246626 )
Cool Vizify Profile at https://www.vizify.com/oz-apps
http://www.giderosmobile.com/forum/discussion/926/how-to-pass-variables-through-event-listeners-039attempt-to-index-a-nil-value039
OzApps - I am already passing data as an extra parameter, my problem is that I want to ALSO get access to data from my class as well. It does not seem possible to pass data from TWO sources through to the event handler.
I've seen several examples where an event handler is declared like so:
function Classname:Event_Handler(eventdata)
local buttonInfo = eventData:getTarget() -- This gives me access to event data
self.xxxx -- But trying to access a property of the class results in nil
end
I suppose my question is - whats the purpose of qualifying an event handler with the name of a class if I can't access class data from within the event handler?
I have already thought of a way around my problem but I am interested to know the answer to the above question.
and if you are using this in a theObj:func type function, then you can replace the theObj with self as it is referencing to the same.
Author of Learn Lua for iOS Game Development from Apress ( http://www.apress.com/9781430246626 )
Cool Vizify Profile at https://www.vizify.com/oz-apps