I am trying to update my Pathfinder Character generator to have the ability to save a character by using HTML5's web storage. I have a JavaScript file used to generate the character.
However, I'm running into a few problems. How can I make it so that only things that have been updated changed when clicking my "Update Character" button? Secondly, what would the best way to go about showing the results?
This is my current code:
function SaveCharacter() {
makeCharacter();
if (typeof(Storage) !== "undefined") {
if (localStorage.used) {
alert("used was true.");
localStorage.name = name;
}
else {
localStorage.used = true;
localStorage.name = name;
localStorage.skill_points = num_skill_points;
localStorage.spells = num_spells;
localStorage.feats = num_feats;
localStorage.hitdie = hit_die;
localStorage.wealth = wealth;
localStorage.Class = Class;
// localStorage.Scores = new Array();
// for (var i = 0; i < n; i++) {
// localStorage.Scores[i] = ability_scores[i];
// }
}
document.getElementById("result").innerHTML="Character Name: " + localStorage.name;
}
else {
document.getElementById("result").innerHTML = "Sorry, your browser does not support web storage...";
}
}
function DeleteCharacter() {
localStorage.clear();
}
When working with this, it changes the name regardless of whether I've deleted the character or not. Also, document.getElementById("result").innerHTML="Character Name: " + localStorage.name; doesn't allow me to update several fields at once. What would be a better way to do this?
[edit] - Here is a link to the generator.