function listener and function from module?

trying to understand how this works…

I want to put functions in separate files and let a trigger event call them.
when I put the function “justDoIt” into same file as event listener it works ok:

SomeLocallyExistingDisplayObject:addEventListener(“touch”, justDoIt)

but it does not work if I do like this:

I put function “justDoIt” into file comeOn.lua.

In main.lua or file with event listener:

local comeOn = require (“comeOn”)

SomeLocallyExistingDisplayObject:addEventListener(“touch”, comeOn.justDoIt)

Would be happy if anyone could shed some light on this:)

[import]uid: 109677 topic_id: 21578 reply_id: 321578[/import]

Hi @une.ulvedal,

Make sure you have:

--make sure everything can see this module  
module(..., package.seeall) in your comeOn.lua file  
  
--and justDoIt is NOT local in your comeOn.lua  
  
 function justDoIt()  
 --do something here  
 end  
  
--then from your main.lua  
  
local comeOn = require("comeOn");  
  
local SomeLocallyExistingDisplayObject = display.newCircle( 150, 150, 15 );  
  
--then try.....  
  
SomeLocallyExistingDisplayObject:addEventListener("touch", comeOn.justDoIt);  
  

That should fix it for ya… :wink:
Happy coding

Larry
[import]uid: 107633 topic_id: 21578 reply_id: 85557[/import]

it was making the function local, good to know how this works, thanks so much! [import]uid: 109677 topic_id: 21578 reply_id: 85570[/import]