I need to be able to save a user's information using localStorage or anything that works really. I don't know a lot about localStorage but I figure in order to store an object in it I would need a function in the object maker. Perhaps I'm wrong, but that's why I'm posting.
I think that you can use localStorage.username(this.username) to store username but I need to now how to store an entire object without using JSON stringify. localStorage.newPlayer()
function Player(username, lvl, exp, expNeeded, nextLevel, gold, hp, atk, def, spd) {
var self = this;
this.username = username;
this.lvl = lvl;
this.exp = exp;
this.nextLevel = nextLevel;
this.expNeeded = expNeeded;
this.gold = gold;
this.fullLife = hp;
this.hp = hp;
this.atk = atk;
this.def = def;
this.spd = spd;
this.implement = function() {
$('#user').text(this.username).addClass('playerName').data('player', self);
$('#username').text("Username: " + this.username);
$('#lvl').text("Level: " + this.lvl);
$('#exp').text("Experience: " + this.exp);
$('#expNeeded').text("Experience Needed: " + this.expNeeded);
$('#gold').text("Gold: " + this.gold);
$('#hp').text("HP: " + this.fullLife);
$('#attack').text("Attack: " + this.atk);
$('#defense').text("Defense: " + this.def);
$('#speed').text("Speed: " + this.spd);
$('#nextLevel').text("Next Level: " + this.nextLevel);
};
this.implement();
}
if($('body').attr("id") == "Home") {
var newPlayer = new Player(prompt("What is your username?"), 1, 0, 10, 10, 0, 10, 2, 1, 1);
}
playerEl = $('.playerName');
player = playerEl.data('player');
If you need to see the full code let me know