I am really confused and I don't even know what I am doing anymore, spent hours on this. All that I want is so that when I make a score in a level, to move on the next level and continue growing. Instead when I go on the next layout, it goes to 0.
The counting works normally each level, when collecting items or killing enemies, but it just gets lost after I move on the next layout. I would appreciate some help, thank you!
Here is what I have so far:
For a score in game you use a global variable that simply retains its value between layouts. There is no need to save the score then load it from local storage on each layout.
Develop games in your browser. Powerful, performant & highly capable.
Yeah but how about when I have also a save function in the game so you can exit the game and return to that layout in another time? How do I keep that global variable too with that save? Does it keep it too? I made the save like 6 months ago so I don't remember much about it.
If it's a running total for the player that you saved then you would load it once from local storage on the first layout of the game so a main menu or load game menu and set global variable to the item loaded.
Ok I fixed it thank you so much! This is how all my localstorage looks like and works the way I need it.
I have one final questions if it is not a problem. If I would like to use these points to buy items for the main character, how could I do it in a way that if the main character dies, they restart the layout with the things that they have already bought in the previous ones?
Currently when character dies, the points go to 0, which I don't mind because it adds an extra layer of difficulty so its more fun to try and stay alive until you spend your money.
But how can I do that so that it keep the items?
How are items added? Usually it would be an array inventory which is global anyway and stores all items. Depends how you are currently adding items to the player.
I see, thanks for everything! :)