creep is not defined?



  • ReferenceError: creep is not defined
    at main:2:4
    at n:5:28406
    at Object.c.runCode:5:34007
    that is the error, what is up?
    and here is the script in main that I was using

    // memory roles
    if(creep.memory.role == 'harvester') {
      harvester(creep);
    }
    if(creep.memory.role == 'builder') {
      builder(creep);
    }
    if(creep.memory.role == 'guard') {
      guard(creep);
    }
    
    if (creep.memory.role == 'harvester'){
        if(creep.carry.energy < creep.carryCapacity) {
            var sources = creep.room.find(FIND_SOURCES);
            creep.moveTo(sources[0]);
            creep.harvest(sources[0]);
        }
        else {
            creep.moveTo(Game.spawns.Spawn1);
            creep.transferEnergy(Game.spawns.Spawn1);
        }
    }
    
    if(creep.memory.role == 'builder') {
      if(creep.carry.energy === 0) {
        creep.moveTo(Game.spawns.Spawn1);
        Game.spawns.Spawn1.transferEnergy(creep);
      }
      else {
        var targets = creep.room.find(FIND_CONSTRUCTION_SITES);
        if(targets.length) {
          creep.moveTo(targets[0]);
          creep.build(targets[0]);
        }
      }
    }
    
      if(creep.memory.role == 'guard') {
        var targets = creep.room.find(FIND_HOSTILE_CREEPS);
        if(targets.length) {
            creep.moveTo(targets[0]);
            creep.attack(targets[0]);
        }
      }
    


  • Is this all there is in your main? If so, how would it know what creep to check? You need to iterate over all the creeps in order to do this.
    So, make loop that loops over Game.creeps and in that loop, run what you have now.

    (P.S. You stole the room I wanted to expand to :P)