gpt4 book ai didi

javascript - 在javascript中使用一种我似乎无法在任何地方找到的localStorage

转载 作者:行者123 更新时间:2023-11-30 15:32:00 24 4
gpt4 key购买 nike

所以我有一个保存和加载功能,我大概一年前就在使用它,但在这个庄园里找不到保存和加载的例子。我的问题是我没有将这些数字保存和加载为整数,但我不记得或找不到我需要做什么才能将这些数字保存/加载为整数。很抱歉提出这样一个微不足道的问题,但这始终是一个很好的去处。

   function saveGame() {
localStorage["ClickMiner.savedBefore"] = savedBefore;
localStorage["ClickMiner.manaRefilCost"] = manaRefilCost;
localStorage["ClickMiner.rocks"] = rocks;
localStorage["ClickMiner.miningXp"] = miningXp;
localStorage["ClickMiner.miningLevel"] = miningLevel;
localStorage["ClickMiner.pickaxes"] = pickaxes;
localStorage["ClickMiner.pebbleGrowers"] = pebbleGrowers;
//localStorage["ClickMiner.rockTier"] = rockTier;
localStorage["ClickMiner.rockTierCost"] = rockTierCost;
localStorage["ClickMiner.bankedRocks"] = bankedRocks;
updateTextBox("Game Saved");
return true;
}

function loadGame() {
savedBefore = (localStorage["ClickMiner.savedBefore"]);
manaRefilCost = (localStorage["ClickMiner.manaRefilCost"]);
rocks = (localStorage["ClickMiner.rocks"]);
miningXp = (localStorage["ClickMiner.miningXp"]);
miningLevel = (localStorage["ClickMiner.miningLevel"]);
pickaxes = (localStorage["ClickMiner.pickaxes"]);
pebbleGrowers = (localStorage["ClickMiner.pebbleGrowers"]);
//rockTier = (localStorage["ClickMiner.rockTier"]);
rockTierCost = (localStorage["ClickMiner.rockTierCost"]);
bankedRocks = (localStorage["ClickMiner.bankedRocks"]);
updateTextBox("Game Loaded");
return true;
}

function newGame() {
savedBefore = 1;
localStorage["ClickMiner.savedBefore"] = savedBefore;
localStorage["ClickMiner.manaRefilCost"] = manaRefilCost;
localStorage["ClickMiner.rocks"] = rocks;
localStorage["ClickMiner.miningXp"] = miningXp;
localStorage["ClickMiner.miningLevel"] = miningLevel;
localStorage["ClickMiner.pickaxes"] = pickaxes;
localStorage["ClickMiner.pebbleGrowers"] = pebbleGrowers;
//localStorage["ClickMiner.rockTier"] = rockTier;
localStorage["ClickMiner.rockTierCost"] = rockTierCost;
localStorage["ClickMiner.bankedRocks"] = bankedRocks;
location.reload();
updateTextBox("New Game Started.");
return true;
}

最佳答案

Localstorage 仅适用于字符串。

parseInt(variable)

应该做的工作

关于javascript - 在javascript中使用一种我似乎无法在任何地方找到的localStorage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42099258/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com