Creep stop moving if source empty



  • Hi forum,

    Really fascinating game, but

    I experience the my creeps stops moving if the desired source is empty until the source is recharged.

    I don't mean this pumping move during charging, I mean moving forward towards the source. When the source is recharged the creeps immediately continue to move their way.

    I would prefer if they would continue even if the source is empty.

    Here the code I use:

    var source = spawn.pos.findClosestByRange(FIND_SOURCES); if(creep.harvest(source) == ERR_NOT_IN_RANGE) {
      creep.moveTo(source);
    }

    Any ideas?


  • Culture

    Check to see what creep.harvest returns. If the source is empty it may be returning ERR_INVALID_TARGET or something instead of NOT_IN_RANGE.



  • The error code if the source is empty is ERR_NOT_ENOUGH_RESOURCES. Instead of checking for creep.harvest(source) == ERR_NOT_IN_RANGE, you could check creep.pos.isNearTo(source)



  • Hey

    You could also check for energy available. With every find function you can add a function to filter your research.

    var source = spawn.pos.findClosestByRange(FIND_SOURCES, {

    filter:(source)=>{ return /*your test here*/ true;}

    });

    if(!source){/**no sources found, do something else*/}

    if(creep.harvest(source) == ERR_NOT_IN_RANGE) {
      creep.moveTo(source);
    }

    http://support.screeps.com/hc/en-us/articles/203079211-Source