【问题标题】:Error when running screeps Script运行 screeps 脚本时出错
【发布时间】:2016-11-14 16:33:26
【问题描述】:

不知道“Screeps”?访问 screeps.com

它是主脚本中的第 11 行

错误:

main:11
      if (creep.transfer(Game.spawns.Spawn1, RESOURCE_ENGERGY) == ERR_NOT_IN_RANGE {
                                                                                   ^
SyntaxError: Unexpected token {

脚本:

module.exports.loop = function () {
    var creep = Game.creeps.Grace;
    if (creep.memory.working == true && creep.carry.energy == 0) {
      creep.memory.working = false;
    }
    else if (creep.memory.working == false && creep.carry.energy == creep.carryCapacity) {
      creep.memory.working = true;
    }

    if (creep.memory.working == true) {
      if (creep.transfer(Game.spawns.Spawn1, RESOURCE_ENGERGY) == ERR_NOT_IN_RANGE {
         creep.moveTo(Game.spawns.Spawn1);
    }
  }
  else {
    var source = creep.pos.findClosestByPath(FIND_SOURCES);
    if creep.harvest(source) == ERR_NOT_IN_RANGE {
      creep.move.To(source);
    }
  }
};

有什么建议吗?

【问题讨论】:

  • ERR_NOT_IN_RANGE 之后至少缺少一个右括号
  • 但是在哪里?我找不到。
  • 您的错误告诉您的确切位置。就在{之前。

标签: javascript screeps


【解决方案1】:

你找到了吗?

就像 RienNeVaPlus(和错误本身)所说,在第 11 行缺少一个右括号:

10 -    if (creep.memory.working == true) {
11 -        if (creep.transfer(Game.spawns.Spawn1, RESOURCE_ENGERGY) == ERR_NOT_IN_RANGE ) {    // If you open the round bracket at the beginning of an IF, you need to close it as well. Right before the curly bracket!
12 -            creep.moveTo(Game.spawns.Spawn1);
13 -        }
14 -    }

但是第 18 行至少还有一个错误:

17 -    if (creep.harvest(source) == ERR_NOT_IN_RANGE) {
18 -        creep.moveTo(source);   // There's no function called 'To()'. You might want to use 'moveTo()'.
19 -    }

【讨论】:

    最近更新 更多