Sorry but i can't find a solution...
but a function defined as "listener" can be part of a class function and can call another class function?
... yes i'm not very clear ...
try to explain with some "stripped" code example:
-- my class
CTNTVirtualPad = Core.class(Sprite)
-- called by listener functions... but got and error
function CTNTVirtualPad:checkPad(event)
print(event)
end
--- LISTENER FUNCTIONS ----
-----------------------
-- Touches begin event --
-----------------------
function CTNTVirtualPad:onTouchesBegin(event)
self:checkPad(Event.TOUCHES_BEGIN)
end
-----------------------
-- Touches move event --
-----------------------
function CTNTVirtualPad:onTouchesMove(event)
self:checkPad(Event.TOUCHES_MOVE)
end
-----------------------
-- Touches end event --
-----------------------
function CTNTVirtualPad:onTouchesEnd(event)
self:checkPad(Event.TOUCHES_END)
end
--- DEFINE EVENT LISTENER
-----------------------
-- start Virutal Pad and events --
-----------------------
function CTNTVirtualPad:start()
stage:addEventListener(Event.TOUCHES_BEGIN, self.onTouchesBegin)
stage:addEventListener(Event.TOUCHES_MOVE, self.onTouchesMove)
stage:addEventListener(Event.TOUCHES_END, self.onTouchesEnd)
end |
when you try to touch the screen of device you get this error:
tntvirtualpad.lua:204: attempt to call method 'checkPad' (a nil value)
stack traceback:
tntvirtualpad.lua:204: in function
but checkPad is not null!!
ahhhhrrrrgggg!
the event is raised correctly but seems that my function checkPad is not defined (nil)
why?

(
EDIT:
obviously if checkPad is defined as "local function" the code works fine...
ex:
local function checkPad(event)
print(event)
end |
:-?
Comments
Likes: Averett
thanks chipster123!!!
i lost some hours around this error...
but my eyes not see this *BIG* and *stupid* code error...
mmm it's better i go to sleep!! doh!!!
thanks again chipster!
www.tntengine.com
My apps: http://www.yummyyellow.com
www.tntengine.com
and driving myself crazy. I was very glad to see @chipster123's post above (thanks!).
I just hope I remember next time I need it. Note to self....