Repair Containers?



  • Hi noob to the game but loving it so far!

    Maybe a silly question but when ever I attempt to repair a container I get error code -7 (Invalid Target) are you not able to repair them or am I doing something stupid?

     

    var repTarget = creep.room.find(FIND_STRUCTURES, {filter: function(object){ return object.structureType === STRUCTURE_ROAD || object.structureType === STRUCTURE_CONTAINER && (object.hits < object.hitsMax); } });

    if (repTarget.length > 0)
    {
    if(creep.repair(repTarget[0]) == ERR_NOT_IN_RANGE)
    {
    creep.moveTo(repTarget[0]);
    }
    }



  • I think you may be trying to repair a fully repaired road.  Some brackets may be useful to force the || to be evaluated before the &&.



  • Thank you, you were correct I was missing brackets which was causing some confusion. 🙂

    For reference to someone in the future looking at this, I should have brackets after the return up till && as below:

     

    {filter: function(object){ return (object.structureType === STRUCTURE_ROAD || object.structureType === STRUCTURE_CONTAINER) && (object.hits < object.hitsMax); }