Punchausen Posted October 19, 2017 Share Posted October 19, 2017 Hi folks, This has me stumped.. I have a variable I have defined for a state called 'loginProgression' var login = function(game) { var promptText, username, lockInNameButton, loginProgression, planet = []; } The purpose of this is that depending on what I've done in the login process (entering a name, choosing an object), it will fire off the new fields. Here's the update function: update: function () { console.log('Login progression is ' + this.loginProgression); switch (this.loginProgression) { case 0: this.requestName(); break; case 2: this.requestPlanet(); break; case 4: console.log("Shouldnt see this"); break; default: break; } } This thing that is confusing me is that once you submit your name, it updates the 'loginProgression' value to 2 - but the console log in 'update' still repeats that it is 1. Checking the variable in the chrome console also shows it to be correctly updated to 2 - so it's as if the 'update' function somehow doesn't notice when a global it's checking constantly changes! Any help on this is much appreciated! Link to comment Share on other sites More sharing options...
samme Posted October 20, 2017 Share Posted October 20, 2017 Probably those are different references. Try storing it in game.loginProgression or window.loginProgression. Link to comment Share on other sites More sharing options...
Punchausen Posted October 20, 2017 Author Share Posted October 20, 2017 Worked a treat, thanks very much! Link to comment Share on other sites More sharing options...
Recommended Posts