The majority of my gameplay code resides in game.lua and this is a Composer scene. Then I also have a good amount of code in player_maker.lua which relates more specifically to the player( ex: lives remaining, movement speed, etc).
My question: What's the best way to make my game.lua module aware that something happened to the player?
For example, if the player lost a life and I updated that value in player_maker.lua, or if the player collided with some particular object and I want the game.lua module to know about, how should I be doing that?
Right now I am doing something like this in my game.lua:
-- INSIDE game.lua local player = player_maker.create() local function updatePlayerLives() lives = player.lives if(player.lives == 0) then --do some stuff end end Runtime:addEventListener("enterFrame", updatePlayerLives)
Is this the best way to make game.lua aware that something changed in player_maker.lua? Or is there a better alternative I should be using?
Since the events I'm checking for do not happen often, it feels like a waste to be using a listener on every frame, but I'm not sure of another easy way to do it.