tomorrowdog Posted December 22, 2017 Share Posted December 22, 2017 I had a state serving as a level in my game. In the middle of one of the functions, it would check in an if statement to see if the criterion for beating the stage had been met and would call a function to change state back to main menu. If I then went from the main menu back to the stage after doing that state change, it'd be a buggy mess. I noticed that the "Quit" button that called a barebones function returning to the main menu didn't give me the same problem. What I tried is that after I did the "win" conditional check, I put the rest of the function in an else statement. And it worked! But I don't understand why and I'm concerned for the future. I thought the problem may have been global variables but I'm almost positive that that isn't true here. The way I understood changing states is that any code beneath it was irrelevant. Am I wrong in that assumption? spawnRoom: function(){ this.screen += 1; if(this.screen == 9){ this.completeGame(); } else{ .... } } completeGame: function(){ this.game.sound.stopAll(); this.state.start('Menu'); } Link to comment Share on other sites More sharing options...
samme Posted January 2, 2018 Share Posted January 2, 2018 On 12/21/2017 at 7:07 PM, tomorrowdog said: The way I understood changing states is that any code beneath it was irrelevant. Am I wrong in that assumption? state.start() works like any other function call — after it completes, control returns to the calling function, and any remaining statements are executed too. Link to comment Share on other sites More sharing options...
Recommended Posts