保存和加载功能只有一半有效吗?

我最近启动了一个Clicker游戏,并设法编写了一个保存和加载游戏脚本...保存和加载功能似乎可以保存和加载我的点击次数(cookie),但不能保存和加载我的自动点击商店(光标和cursorCost),我想知道是什么我做错了吗?

var cookies = 0;

function cookieClick(number){
    cookies = cookies + number;
    document.getElementById("cookies").innerHTML = cookies;
} 

var cursors = 0;

function buyCursor(){
    var cursorCost = Math.floor(25 * Math.pow(1.5,cursors));     //works out the cost of this cursor
    if(cookies >= cursorCost){                                   //checks that the player can afford the cursor
        cursors = cursors + 1;                                   //increases number of cursors
        cookies = cookies - cursorCost;                          //removes the cookies spent
        document.getElementById('cursors').innerHTML = cursors;  //updates the number of cursors for the user
        document.getElementById('cookies').innerHTML = cookies;  //updates the number of cookies for the user
    } else {
        alert("Unfortunately you cannot afford that!");
    }
    var nextCost = Math.floor(25 * Math.pow(1.5,cursors));       //works out the cost of the next cursor
    document.getElementById('cursorCost').innerHTML = nextCost;  //updates the cursor cost for the user
}

window.setInterval(function(){

    cookieClick(cursors);

}, 1000);


function reset() {
  document.getElementById("cursors").reset();
  document.getElementById("cookies").reset();
}

function save() {
localStorage.setItem('cookies', cookies);
localStorage.setItem('cursors', cursors);
localStorage.setItem('cursorCost', cursorCost);
}

function load() {
cookies = localStorage.getItem('cookies');
cookies = parseInt(cookies);
cursors = localStorage.getItem('cursors');
cursors = parseInt(cursors);
cursorCost = localStorage.getItem('cursorCost');
cursorCost = parseInt(cursorCost); 
update();
}
评论