Runtime Touch Listeners in External Module

Hi,

I have been following this tutorial for creating various reusable objects within my games. To keep everything simple, would it be best to keep the runtime touch listeners within the modules, or place them on each individual object when it is called in the main.lua?

I ask this because I have been having issues assigning colon operator functions to Runtime events in the modules, as they are throwing all sorts of errors at me.

Thanks!

Do you mean runtime or object listeners?  There is a huge difference.  For example obj:addEventListener(“touch”) will only apply to that object where as runtime:addEventListener(“touch”) will apply to the entire screen.  Many objects can share the same events and you can use event.target to work out which object raised the event.

It is a question of scope (do some research on this) and the goal is to keep properties, functions and events limited in scope as much as possible.  This makes projects MUCH more manageable and bug free when you make larger more complex apps.

Hope this helps.

Put everything in the class for the object if you can.   That way it is easier to find and move around or use in other places.  

function thisclass:addlistener( ) self.buttonGroup:addEventListener( "touch" , self.touch\_back ) return end

Do you mean runtime or object listeners?  There is a huge difference.  For example obj:addEventListener(“touch”) will only apply to that object where as runtime:addEventListener(“touch”) will apply to the entire screen.  Many objects can share the same events and you can use event.target to work out which object raised the event.

It is a question of scope (do some research on this) and the goal is to keep properties, functions and events limited in scope as much as possible.  This makes projects MUCH more manageable and bug free when you make larger more complex apps.

Hope this helps.

Put everything in the class for the object if you can.   That way it is easier to find and move around or use in other places.  

function thisclass:addlistener( ) self.buttonGroup:addEventListener( "touch" , self.touch\_back ) return end