gpt4 book ai didi

javascript - 运行 screeps 脚本时出错

转载 作者:太空宇宙 更新时间:2023-11-04 16:21:51 25 4
gpt4 key购买 nike

不知道“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);
}
}
};

有什么建议吗?

最佳答案

你找到了吗?

就像 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 - }

关于javascript - 运行 screeps 脚本时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40564709/

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