*SOLVED*
needed to put buildings: game.buildings
Hello,
Below I got my save and load functions for a game that I'm following a tutorial for. It works as it should, the money is both saved and loaded.
In the same way as I save and load money I want to save and load an array, game.buildings[0]: game.buildings[0]
How do I go about this? I've been at it the whole day and my eyes are blood shot and I haven't found anything on the internet which is helping me get any closer to getting this fixed. Please if you got anything that can help, share, it's greatly appreciated and will help me sleep at night.
Full code in jsfiddle, http://jsfiddle.net/vmfgn98d/
Though even when I take the faulty code out, the game doesn't work in Jsfiddle so im just posting in case u want to see full code...
needed to put buildings: game.buildings
Hello,
Below I got my save and load functions for a game that I'm following a tutorial for. It works as it should, the money is both saved and loaded.
In the same way as I save and load money I want to save and load an array, game.buildings[0]: game.buildings[0]
How do I go about this? I've been at it the whole day and my eyes are blood shot and I haven't found anything on the internet which is helping me get any closer to getting this fixed. Please if you got anything that can help, share, it's greatly appreciated and will help me sleep at night.
Code:
function save() { var save = { game: { money: game.money, } }; localStorage.setItem("save", JSON.stringify(save)); }; function load() { var GameTwo = JSON.parse(localStorage.getItem("save")); if (typeof GameTwo.game.money !== "undefined") game.money = GameTwo.game.money; document.getElementById("money").innerHTML = game.money; };
Full code in jsfiddle, http://jsfiddle.net/vmfgn98d/
Though even when I take the faulty code out, the game doesn't work in Jsfiddle so im just posting in case u want to see full code...