Local storage array function

Started on the old forum in January 2015 · view the original in the archive · old links redirect here

No replies · 71 views · started 11 years ago · 1 min read

MonkeyJava Newbie · 1 posts #1

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.

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...

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close