Variables reset when changing states



  • Hey all I need some assistance

    I'm working on a clicker/idle type game, and here's my problem: when I go into a state then leave the state and comeback later, the value resets to 0.
    I assume it's something simple to fix but I've been stuck on it for a while. :/



  • It would a whole new state when you leave one and come back later.
    Seriously don't save anything that stays there for as long as the game is running in a state.
    You need to save your variables some where else.
    Maybe as a static variable in some class like this, for example score is a static variable in Stats class:

    Stats.score = 0;
    


  • I think the Reg class is for static variables like that. If you used the template it would have example variables in it.

    class Reg{
    public static var coins:Int = 0;
    }



  • I think the newest templates don't come with the Reg class.


Log in to reply