Jump to content

localStorage Array


DerekBogie
 Share

Recommended Posts

I am attempting to use a localStorage array as a set of 20 binary switches so to say. The entire length of the area will be set to 0 all the way thru and I need to be able to switch individual array elements to 1.

 

Basically this is what I have started with in the beginning.

 localStorage.dragonEggs = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];

There are 20 eggs throughout the maps. When you find a certain one, lets say egg 4. In the function I used ,

localStorage.dragonEggs[3] = 1;

I am not sure since it is a localStorage Variable if i can do it this way or not? when I check my developer console it still shows all 20 elements at 0.

Link to comment
Share on other sites

Alright, that makes more sense. How would you suggest using the getItem and setItem methods to be able to save 20 localStorage variables with this method and not need to overload the localStorage variables onto players memory? If possible I would like to find a way to save 20 different variables with different values with localstorage. without having to make a new localstorage variable for each different value. That is why I thought an array would work best.

Edited by DerekBogie
Link to comment
Share on other sites

You're already using an array. Just set / get that. You'll have to serialize / unserialize it though.

http://html5doctor.com/storing-data-the-simple-html5-way-and-a-few-tricks-you-might-not-have-known/

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...