Hello everyone!
In my game I have different game modes.
Every game mode is a different lua file with composer scena.
The files have the following structure:
--modules that I use for all modes local allModule\_1 = require("allModule\_1") local allModule\_2 = require("allModule\_2") local allModule\_3 = require("allModule\_3") --modules that I use only for this mode local thisModModule\_1 = require("thisModModule\_1") local thisModModule\_2 = require("thisModModule\_2") local thisModModule\_3 = require("thisModModule\_3") --variables that I use for all modes local allVar\_1 local allVar\_2 local allVar\_3 --variables that I use only for this mode local thisModVar\_1 local thisModVar\_2 local thisModVar\_3 --functions with the same code for all the mods that use the same variables (es. thisModVar\_1) for all the mods. --However, these variables (es. thisModVar\_1) can be modified by personal methones of a mod (es. "enterFrame") local function gameOver() end local function pause() end local function resume() endimprove use of composer for different game modes --Different functions that change according to the modality and modify both variables (es. allVar\_1 and thisModVar\_1) local function enterFrame(event) end local function other1( group ) end local function other2() end --Naturalmete created different things according to the modality function scene:create( event ) end function scene:show( event ) end function scene:hide( event ) end function scene:destroy( event ) end
Therefore in essence for each mode I copy some identical functions and some equal variables. The problem of course and that if I have to make a change I have to do it all.
Is there a way to optimize this?