Josqu
Josqu

Reputation: 31

Error when running screeps Script

Don't know about "Screeps"? Visit screeps.com

Its the 11 line line in the main script

The Error:

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

Script :

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

Any suggestions?

Upvotes: 1

Views: 254

Answers (1)

nehegeb
nehegeb

Reputation: 193

Did you find it yet?

Just like RienNeVaPlus (and the error itself) tells, in line 11 there's a closing bracket missing:

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

But there's at least one more error in line 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 -    }

Upvotes: 1

Related Questions