I often find it convenient in Codea to create class variables for particular screens in the game I’m coding, so to take an example I might use “self.playerx” within a screen that’s defined by the class FightAnim(), being the x position I want the player to be on that screen. That way I don’t need to worry about any other playerx variables conflicting with it, because for the most part I only want to use it when that screen is showing. However I get very mixed results when occasionally I try to reference that variable from another class. So in my FightResults() class, if I just want to use that variable I will use FightAnim.playerx. Sometimes this technique seems to work, and sometimes it just generates a nil value even though I know it’s definitely been defined.
I normally work around it by using a sufficiently precise global variable but I’ve just had a situation where in the process of refactoring some code a stretch of code that referenced FightAnim.playerx has stopped working when it worked perfectly before! It says FightAnim.playerx is a nil value. The bizarre thing is that if I go into the FightAnim() class and laboriously swap all refs to self.playerx for FightAnim.playerx then suddenly it works and my other class can “find” the supposedly undefined variable. I thought that unless you’re using a defined instance of FightAnim() then FightAnim.playerx and self.playerx (used within the class) should be two ways of saying exactly the same thing. Am I wrong?
I can’t work out what I’m doing differently so I’m wondering if there’s some syntax to these classes that I don’t know. Can anyone help?