2016-11-12 146 views
1

不知道「Screeps」?訪問screeps.com運行screeps時出錯腳本

其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); 
    } 
    } 
}; 

有什麼建議?

+0

你」在'ERR_NOT_IN_RANGE'後面至少丟失了一個右括號, –

+0

但是在哪裏?我找不到。 – Josqu

+0

確切地說,你的錯誤告訴你它是。在'{'之前。 –

回答

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