So I have developed a few games so far using Corona SDK, but in all of them I have used global variables to access variables throughout the program. Now I realize this is bad practice so in my next game I want to only use local. However, I do not really get how you do that.
My confusion is, for example, I always have a gameplay class (object oriented in a separate file) that has the background class, character class, enemy class, etc as properties. I store an instance of this gameplay class as a global so I can access everything in every class. (I think this is called a singleton or something). My trouble is that I can’t require the gameplay class in every class because then it would require the current file - recursion! Also wouldn’t it just make a new copy of the gameplay class?
Ex: if I try to access the character in the background class I would have to require the gameplay class which would just make another copy of the gameplay class. Also in the required gameplay class, the background class would be required again-> recursion occurs.
As you can tell I am very confused.
Hopefully that made sense and someone can explain.
Thanks,
David