I'm developping a mobile game so i want to store the game progress for every logged in user ( if a player is in the mid game and accidentally closes the web browser. Once he opens the game again, the game starts from the beginning and the game that the player was playing is lost. In this way, players can resume their game later.)
So for every user i'll create a new localStorage object but i get this answer here Data supported by HTML5 Local Storage by "Jocelyne lecopmte" .
So it's not possible to do it ? if not how can'i do it so ? Thank you in advance
That will work fine for any single player aspects of the game. You can use JSON.stringify and JSON.parse to save and load objects from localStorage.
var object = new Object();
object.score = 100;
object.name = "John";
localStorage.setItem("player1", JSON.stringify(object));
var copy = JSON.parse(localStorage.getItem("player1"));
console.log(copy.name);
Working code can be found here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With