从Code.org数据表中检索数组

时间:2019-05-09 18:11:08

标签: javascript code.org

我正在code.org的应用程序实验室中制作一个简单的Clicker游戏,并希望在关闭应用程序时设计一个保存功能,但是在从表中检索数组时遇到了问题

var upgrade = [0,0,0,0,0,0,1];
var score = 0;
var cost = [10,30,100,900,10000,810000,5];
var net = 0;
var mult = [0,0,0,0,0,0,1];
var day = 0;
var year = 0;
var tot = 0;
var totMult = 1;
var names = [];
var s = 100000;
readRecords('saveData', {}, function(records){
  for(var i = 0; i< records.length; i++){
    if(getUserId() == records[i].userId){
      console.log(records[i]);
      upgrade = records[i].upgrade;
      score = records[i].score;
      cost = records[i].cost;
      net = records[i].net;
      mult = records[i].mult;
      day = records[i].day;
      year = records[i].year;
      tot = records[i].tot;
      totMult = records[i].totMult;
      names = records[i].names;
      s = records[i].s;
      setScreen("gameScreen");
      for(var j = 0; j<upgrade.length;j++){
        setText('shop'+j+'cnt', 'Current: '+upgrade[j]);
        setText('shop'+j, '$'+cost[j]);
      }
      console.log('loaded user: '+records[i].userId);
      timedLoop(1000, function(){
      auto();
      if(upgrade[5]==1){
        stopTimedLoop();
        timedLoop(500, function(){auto()});
      }
      hideElement('loading');
    });
    }
  }
  playSound("Puzzle-Dreams.mp3", true);
});

从console.log(records [i])显示的数组应该显示完整的数组,但显示的是[null,null,null]

0 个答案:

没有答案