eventListener don't work with a module

hi,

i don’t understand why my eventlistener don’t work in this case. I have several file from the same structure and in this case with the event that don’t work… what i’m doing wrong ?

thanks for your help.

--viseur.lua local viseur={} local viseur\_mt = { \_\_index = viseur } --set metatable -------------------------------------------------------------------------------- -- public function -------------------------------------------------------------------------------- function viseur.draw( group,posx,posy,x,y )     local e={} --e for viseurlua     e.body=display.newRect(group,posx,posy,x,y)     e.body:setFillColor(1,0,0)     e.body.isVisible=false     return setmetatable ( e,viseur\_mt ) end function viseur:follow(ev) --ev for event     if ev.phase == "began" then         self.body.isVisible=true         self.body.x,self.body.y=ev.x,ev.y     elseif ev.phase == "moved" then         self.body.x,self.body.y=ev.x,ev.y     elseif ev.phase =="ended" then         self.body.isVisible=false     end end return viseur

--main.lua local viseur=require("viseur") local viseurs local backgrounds =.... local backgroundGroup = display.newGroup() local function drawViseur()     viseurs=viseur.draw(backgroundGroup,100,100,50,50) end drawViseur() backgrounds.body:addEventListener( "touch",function() viseurs:follow(event) end) --backgrounds.body works - i don't put the example file in the code not to confuse

I do not understand is that the above example does not work while it yes … it is nevertheless the same principle

--viseur.lua local viseur={} local viseur\_mt = { \_\_index = viseur } --set metatable -------------------------------------------------------------------------------- -- public function -------------------------------------------------------------------------------- function viseur.draw( group,posx,posy,x,y )     local e={} --e for viseurlua     e.body=display.newRect(group,posx,posy,x,y)     e.body:setFillColor(1,0,0)     e.body.isVisible=false e.follow=function(ev)  if ev.phase == "began" then         e.body.isVisible=true         e.body.x,e.body.y=ev.x,ev.y     elseif ev.phase == "moved" then         e.body.x,e.body.y=ev.x,ev.y     elseif ev.phase =="ended" then         e.body.isVisible=false     end end     return setmetatable ( e,viseur\_mt ) end return viseur ----------------------------------------------------------------------------------- --main.lua local viseur=require("viseur") local viseurs local backgrounds =.... local backgroundGroup = display.newGroup() local function drawViseur()     viseurs=viseur.draw(backgroundGroup,100,100,50,50) end drawViseur() backgrounds.body:addEventListener( "touch",viseurs.follow) --backgrounds.body works - i don't put the example file in the code not to confuse

try

backgrounds.body:addEventListener( "touch",viseurs:follow) 

instead of

backgrounds.body:addEventListener( "touch",viseurs.follow)  

 (there is a : instead of a . when calling viseurs:follow

hi Alan Quiz Tix,

thanks for your response but i have tried yet before and i have this error : function argument exepected near “(”

I do not understand is that the above example does not work while it yes … it is nevertheless the same principle

--viseur.lua local viseur={} local viseur\_mt = { \_\_index = viseur } --set metatable -------------------------------------------------------------------------------- -- public function -------------------------------------------------------------------------------- function viseur.draw( group,posx,posy,x,y )     local e={} --e for viseurlua     e.body=display.newRect(group,posx,posy,x,y)     e.body:setFillColor(1,0,0)     e.body.isVisible=false e.follow=function(ev)  if ev.phase == "began" then         e.body.isVisible=true         e.body.x,e.body.y=ev.x,ev.y     elseif ev.phase == "moved" then         e.body.x,e.body.y=ev.x,ev.y     elseif ev.phase =="ended" then         e.body.isVisible=false     end end     return setmetatable ( e,viseur\_mt ) end return viseur ----------------------------------------------------------------------------------- --main.lua local viseur=require("viseur") local viseurs local backgrounds =.... local backgroundGroup = display.newGroup() local function drawViseur()     viseurs=viseur.draw(backgroundGroup,100,100,50,50) end drawViseur() backgrounds.body:addEventListener( "touch",viseurs.follow) --backgrounds.body works - i don't put the example file in the code not to confuse

try

backgrounds.body:addEventListener( "touch",viseurs:follow) 

instead of

backgrounds.body:addEventListener( "touch",viseurs.follow)  

 (there is a : instead of a . when calling viseurs:follow

hi Alan Quiz Tix,

thanks for your response but i have tried yet before and i have this error : function argument exepected near “(”