Best way to make global variables



  • Is there a convention in how to store global variables? current level, statistics, and all that?
    I figure a lot of ways to do it, I'd like to stick to the haxeflixel convention if there is one.



  • Looking at the demos, most of them seem to have a class called Reg.hx and store those variables as public static.

    I think those are mainly the older demos like flappybalt, mode and minimalistTD, where Reg.hx was created automatically by flixel-tools - so don't feel enforced to use that name.

    Author of Discover Haxeflixel | The #1 book to learn HaxeFlixel!
    @leongotgame

    0


  • I use the Reg option and if it is something I want to keep between sessions I will Reg with FlxSave



  • Personally, I use a Game.hx for that. I split game mechanics into classes and put them into a system package and Game.hx then create them at the start of the game. (Something like singleton even though that it's not recommended but it's pretty clean and works for me)



  • @MegaLeon you can also use inline public static to make them read only

    Personally I have my own registry class called Constants.hx


  • administrators

    Note that inline only works for basic types. You can use (default, null) (read-only outside of this class) properties for the rest.


Log in to reply