javascript - saving and loading variables -
i made game , type of game takes hours complete. browser game. how can store variables ( need store 20-40 variables ) , load them using cookies ? ( can access them if browser closed , opened again ). please, need help.
you better off using localstorage , not cookies. pretty simple if like
//the defaults user starts var _defaults = { level : 1, username : null, life : 100 }; //getting previous values storage var saveddetails = localstorage.settings ? json.parse(localstorage.settings) : {}; var settings = $.extend({},_defaults, saveddetails); if(!settings.username) { //set username , save settings.username = window.prompt("name"); } else { //username there hi console.log("welcome " + settings.username); } //save local storage since made changes localstorage.settings = json.stringify(settings);
Comments
Post a Comment