首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >运行screeps脚本时出错

运行screeps脚本时出错
EN

Stack Overflow用户
提问于 2016-11-12 15:59:11
回答 1查看 225关注 0票数 1

不知道什么叫“沉睡”?访问screeps.com

它是主脚本中的11行

错误:

代码语言:javascript
复制
main:11
      if (creep.transfer(Game.spawns.Spawn1, RESOURCE_ENGERGY) == ERR_NOT_IN_RANGE {
                                                                                   ^
SyntaxError: Unexpected token {

剧本:

代码语言:javascript
复制
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);
    }
  }
};

有什么建议吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-11-14 08:33:26

找到了吗?

正如RienNeVaPlus (以及错误本身)所告诉的,在第11行中缺少一个结束括号:

代码语言:javascript
复制
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行中至少还有一个错误:

代码语言:javascript
复制
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 -    }
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40564709

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档