Issue with creep.moveTo



  • I have a harvester module

    module.exports = function(creep) {
    
        if(creep.energy < creep.energyCapacity) {
            var sources = creep.room.find(FIND_SOURCES);
            creep.moveTo(sources[3]);
            creep.harvest(sources[3]);
            }
        else {
            creep.moveTo(Game.spawns.Spawn1);
            creep.transferEnergy(Game.spawns.Spawn1)
        }
    
    }
    

    and I have a tower module

    module.exports = function(creep,towerStart) {
    
         var enemy = creep.pos.findClosest(FIND_HOSTILE_CREEPS);
        if(enemy) { 
            creep.rangedAttack(enemy);
        }
    
         creep.moveTo(TowerStart, 32);
    }
    

    But when I run both of them, my harvesters instead of harvesting materials, they movetTo the area where my towers are supposed to go and my towers do not move. It's not a problem with memory because if I take out that moveTo in the tower module both creep types work fine.



  • What does your main look like? At least the bit that calls these functions.

    I think it were mentioned that the last moveTo specified is the one that affects the creep, so it sounds like the way you're matching towers is set up wrong somehow.



  • I don't know what your problem is. But maybe TowerStart shouldn't be capitalized at the beginning.



  • I figured out the problem

    in main I put if(creep.memory.role = 'tower') instead of if(creep.memory.role == 'tower') i forgot to add a = sign to switch from an assignment operator to a logical equals operator. Thanks guys!