Sign in to follow this  
Wunderforce

Restarting a Phaser State is Resetting Global Variables

Recommended Posts

I have a global object called "params" that stores a lot of important parameters for my game.  I define params in a "main.js" file that initializes the game, defines my states and parameters, and then calls my "bootState". 

For some reason, when I restart my "gameState" (another state, defined in "gameState.js") it resets my "params" object to the values it was initialized with in "main.js".

My goal is to change some parameters via "params" in the console, then restart "gameState" and have it reflect those changed parameters.

If needed I can provide some example code.

Share this post


Link to post
Share on other sites

Are you re-declaring or initializing your variable in gameState?  

So if you had a  var score;  in main.js,  are you initializing it as score =0; or var score =0; in your gameState?

Share this post


Link to post
Share on other sites

Personally I prefer old threads stay up so people with the same problem can read them and figure out where they're going wrong. They fall down the list pretty quickly so will be buried before you know it :)

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

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.