Passing Variables Using Globals - HTML5

I’m using some global variables like maxhealth, mainweaponlvl and current level so that in game you can do this:

Play level one and accumulate coins
Go to upgrade menu and spend coins on upgrades, global values are updated for all things that are upgraded.
Play next level and at the beginning of the level the player stats are set equal to the global variables.

I’m having big problems with the global variables not changing properly? I look through the code a lot but can’t see any obvious issues… Is there a problem with using global variables in this way? And also, is there a way to pass variables between scenes without using global variables?

Hi Mats.

If I understand you correctly, it shouldn’t be a problem, global variables is meant to be used globally in the game to store information globally for the whole game. So if you add something to a global variable in the first scene, it should be the same for every scene in the whole game unless you change it.
I’w experienced sometime in HTML5, the global variables doesn’t work properly in preview, but it works in the exported game

I guess you can pass variables between scenes without global variables if you write the value of the variable in to a txt file, and at the beginning of the second scene you can read the value from the txt file in to the variable but I’m not sure if it possible in HTML5, but we have the option under storage category to do so :wink:

Global variables should work properly, let me know if you think there is a bug somewhere.