put event and a variable in the same function

Hi,

i have this problem, i can’t have the parameter “event” and  another parameter in the same function with these external module.

What is the good syntax for do that ?

Thanks

--viseur.lua local viseur={} local viseur\_mt = { \_\_index = viseur } --set metatable function viseur.draw()       local e={} --e for viseur.lua       e.name="viseur"       e.follow = function(p) --p for players             print(p.x)       end       e.animate=function(event)             if event.phase == "began" then                   print("began")             end       end       e.follower = function(event, p)             print(p.x)             if event.phase == "began" then                   print("began")             end       end        return setmetatable ( e,viseur\_mt ) end return viseur ---------------------------------------------------------------------------------- ---------------------------------------------------------------------------------- --main.lua local viseur=require("viseur") local viseurs=viseur.draw local background=..... local players=..... background:addEventListener( "touch", viseurs.animate ) --ok background:addEventListener( "touch", function() viseurs.follow(players) end) --ok --this below don't work background:addEventListener( "touch", function() viseurs.follower(event,players) end) --event don't work

Hey espace3d,

I think it’s quite simple, you need the event parameter in your function header as well.

Try the following:

background:addEventListener( "touch", function(event) viseurs.follower(event,players) end)

Just keep in mind you won’t be able to remove that touch handler if you need to. Anonymous functions can’t be removed by calling :removeListener().

So the better solution would be:

local function addFollower(event) viseurs.follower(event, players) end background:addEventListener( "touch", addFollower )

Like this you can remove the listener with:

background:removeEventListener( "touch", addFollower )

hi torbenratzlaff and rob,

thanks a lot for your response. I have learn something else.

to thank you i would share some treasure that i have discovered today on the android store, it’s the game “alto” and “last horizon” from the self develloper.

the graphism and sounds is very nice, the game also… a nugget that can inspire you for your games

https://play.google.com/store/apps/details?id=com.noodlecake.altosadventure

https://play.google.com/store/apps/dev?id=9078867188205035581

Hey espace3d,

I think it’s quite simple, you need the event parameter in your function header as well.

Try the following:

background:addEventListener( "touch", function(event) viseurs.follower(event,players) end)

Just keep in mind you won’t be able to remove that touch handler if you need to. Anonymous functions can’t be removed by calling :removeListener().

So the better solution would be:

local function addFollower(event) viseurs.follower(event, players) end background:addEventListener( "touch", addFollower )

Like this you can remove the listener with:

background:removeEventListener( "touch", addFollower )

hi torbenratzlaff and rob,

thanks a lot for your response. I have learn something else.

to thank you i would share some treasure that i have discovered today on the android store, it’s the game “alto” and “last horizon” from the self develloper.

the graphism and sounds is very nice, the game also… a nugget that can inspire you for your games

https://play.google.com/store/apps/details?id=com.noodlecake.altosadventure

https://play.google.com/store/apps/dev?id=9078867188205035581