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

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -