Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
TOUCHES_END event does not recieve any arguments — Gideros Forum

TOUCHES_END event does not recieve any arguments

dddentdddent Member
edited April 2014 in General questions
Hello,

I have this code:
function button:onTouchesEnd(event)
	print(type(event))
	if button:hitTestPoint(event.touch.x, event.touch.y) then
		Event:dispatchEvent(Event.new("hello"))
		print("hello")
	end
end
 
button:addEventListener(Event.TOUCHES_END, button.onTouchesEnd)
and am getting this error:
main.lua is uploading.
Uploading finished.
nil
main.lua:27: attempt to index local 'event' (a nil value)
stack traceback:
	main.lua:27: in function <main.lua:25>
I compared my code to working code of mine and can't figure out what's wrong with this...

I hope s.o. can tell me what I'm doing wrong.

Thanks
David

Comments

  • keszeghkeszegh Member
    edited April 2014
    shouldn't it be
    button:addEventListener(Event.TOUCHES_END, button.onTouchesEnd, self)
    in the last line?

    also
    self:hitTestPoint(event.touch.x, event.touch.y)

    Likes: dddent

    +1 -1 (+1 / -0 )Share on Facebook
  • shouldn't it be
    button:addEventListener(Event.TOUCHES_END, button.onTouchesEnd, self)
    in the last line?

    also
    self:hitTestPoint(event.touch.x, event.touch.y)
    Yeah, youre right, thanks, but the error keeps coming up, the problem is, that there is nothing passed to the function, and i dont know why...
  • keszeghkeszegh Member
    Accepted Answer
    try
    button:addEventListener(Event.TOUCHES_END, button.onTouchesEnd, button)
    or
    self:addEventListener(Event.TOUCHES_END, button.onTouchesEnd, self)
    inside a button:... function

    Likes: dddent

    +1 -1 (+1 / -0 )Share on Facebook
  • Ok,
    button:addEventListener(Event.TOUCHES_END, button.onTouchesEnd, button)
    worked, thanks! :)

    Passing button instead of self makes sense, but shouldn't the event alsways pass the table with the touch coordinates, and the error shoud have been that self had a nil value? I understand why I have to pass button, but I don't understand why that solved the error...
  • hgvyas123hgvyas123 Guru
    edited April 2014
    i think if you do this
    button:addEventListener(Event.TOUCHES_END, button.onTouchesEnd)
    then in the self it passes the event as
    function button:onTouchesEnd(event)
    	print(type(event))
    	if button:hitTestPoint(event.touch.x, event.touch.y) then
    		Event:dispatchEvent(Event.new("hello"))
    		print("hello")
    	end
    end
    can be also written as
    function button.onTouchesEnd(self,event)
    	print(type(event))
    	if button:hitTestPoint(event.touch.x, event.touch.y) then
    		Event:dispatchEvent(Event.new("hello"))
    		print("hello")
    	end
    end
    :)
    +1 -1 (+2 / -0 )Share on Facebook
Sign In or Register to comment.