Global Variables across states

Recommended Posts


I've created a game which is pretty cool ( for me ) but I'm stuck now on the simplest of things. How do I run global variables across the different level states.

the variables I want to use are; highscore, score, lives

Where in the code do i declare these variables? I've tried a load of things but can't seem to crack it.


Any help would be appreciatd and let me know if I need to explain more.


Share this post

Link to post
Share on other sites

Look at the templates included with Phaser.  One of them, I forget which, shows one way to do this.  It is in the boot state and essentially involves declaring Basicgame.highscore or whatever.  That variable is global.  It doesn't have to be declared in boot but that makes it available right from the offset so is a good place.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.