保存系统Javascript

时间:2015-12-22 00:14:16

标签: javascript html save

我在html中制作一个简单的IDLE游戏,但我真的想制作一个保存系统。所以我尝试使用localStorage但是如果我打开我的网页就会出现NaN ...有人知道如何修复它吗?

代码:

function save(){
    localStorage.setItem("Money", Money);
    localStorage.setItem("DrinksSold", DrinksSold);
    localStorage.setItem("Price", Price);
    localStorage.setItem("Plants", Plants);
    localStorage.setItem("CompetitorBonus", CompetitorBonus);
    localStorage.setItem("Meals", Meals);
    localStorage.setItem("MealsLeft", MealsLeft);
    localStorage.setItem("MealCost", MealCost);
    localStorage.setItem("Werknemers", Werknemers);
    localStorage.setItem("WerknemerCost", WerknemerCost);
    localStorage.setItem("nextCostWerknemer", nextCostWerknemer);
    localStorage.setItem("StreetLicenses", StreetLicenses);
    localStorage.setItem("StreetLicensesHomeTown", StreetLicensesHomeTown);
    localStorage.setItem("StreetLicenseCost", StreetLicenseCost);
    localStorage.setItem("nextCostStreetLicense", nextCostStreetLicense);
    localStorage.setItem("HigherPriceCost", HigherPriceCost);
    localStorage.setItem("nextHigherPriceCost", nextHigherPriceCost);
    localStorage.setItem("PlantCost", PlantCost);
    localStorage.setItem("nextPlantCost", nextPlantCost);   
    localStorage.setItem("nextMealCost", nextMealCost);
    localStorage.setItem("DestroyCompetitorCost", DestroyCompetitorCost);
}


function load_game(){
    if(typeof(localStorage.getItem("game_saved_before")) != undefined){
    Money = parseInt(localStorage.getItem("Money"));
    DrinksSold = parseInt(localStorage.getItem("DrinksSold"));
    Price = parseInt(localStorage.getItem("Price"));
    Plants = parseInt(localStorage.getItem("Plants"));
    CompetitorBonus = parseInt(localStorage.getItem("CompetitorBonus"));
    Meals = parseInt(localStorage.getItem("Meals"));
    MealsLeft = parseInt(localStorage.getItem("MealsLeft"));
    MealCost = parseInt(localStorage.getItem("MealCost"));
    Werknemers = parseInt(localStorage.getItem("Werknemers"));
    WerknemerCost = parseInt(localStorage.getItem("WerknemerCost"));
    nextCostWerknemer = parseInt(localStorage.getItem("nextCostWerknemer"));
    StreetLicenses = parseInt(localStorage.getItem("StreetLicenses"));
    StreetLicensesHomeTown = parseInt(localStorage.getItem("StreetLicensesHomeTown"));
    StreetLicenseCost = parseInt(localStorage.getItem("StreetLicenseCost"));
    nextCostStreetLicense = parseInt(localStorage.getItem("nextCostStreetLicense"));
    HigherPriceCost = parseInt(localStorage.getItem("HigherPriceCost"));
    nextHigherPriceCost = parseInt(localStorage.getItem("nextHigherPriceCost"));
    PlantCost = parseInt(localStorage.getItem("PlantCost"));
    nextPlantCost = parseInt(localStorage.getItem("nextPlantCost"));
    nextMealCost = parseInt(localStorage.getItem("nextMealCost"));
    DestroyCompetitorCost = parseInt(localStorage.getItem("DestroyCompetitorCost"));
    localStorage.setItem("game_saved_before","true");
    }
}
load_game();
setInterval(save,10);

我知道NaN'不是数字'意味着我通过互联网搜索但是找不到任何可能获得数字的方法?我使用了parseInt,但这似乎不起作用......

0 个答案:

没有答案