Hi!
I'm trying to save game data in JavaScript, using "localStorage".
I have a class called "Entity" with its own variables and functions. I have an array called "loadedEntities" which contains instances of the Entity class. For example
var zombie = new Entity(args)
var spider = new Entity(args)
loadedEntities = [zombie, spider]
I want to save the entirety of "loadedEntities." To do this, I use JSON.stringify(loadedEntities). (I save the entire array in one big gulp) Then, when I want to load the data back into the game, I use JSON.parse(). (My load function sets loadedEntities equal to whatever JSON.parse() returns.)
Now, whenever I try to run a function on an entity, (The entity class has its own functions. So, loadedEntities[0].move() or loadedEntities[1].attack()) I get the following error:
loadedEntities[i].attack is not a function
//i is a good and proper variable. Everything works fine when a "New Game" is selected. The issue definitly has to do with saving
My theory is that when I save instances of the Entity class, the data might get saved but the functions, like "attack()" don't get saved or something. I don't know, what do you guys think?