Healer not finding creeps?



  • I just made my healer role, but its not healing anything or moving. Here is my code:

    if(creep.memory.role == "medic") {
                var damagedCreeps = creep.room.find( Game.MY_CREEPS, {
                filter: function(creep) {
                    return ( creep.hits < creep.hitsMax );
                } } );
                if (damagedCreeps.length > 0){
                    creep.heal(damagedCreeps[0]);
                } else {
                    creep.moveTo(Game.spawns.Spawn1);
                }
            } 
    

    Any tips?



  • @boltz Let's try to indicate to console. damageedCreeps.length, creep.body, the value returned by creep.heal(need HEAL part)



  • All creeps that are the healer class have Heal part, when I check console, the even though there are damaged creeps, the console says that there are none. I don't know how to find the health of that single creep though the log. The bug is probably a mistake in finding the creeps that are damaged. Also, the creep IS moving to spawn, (I tested this by creating a creep far away from spawn in training mode), so I think the problem is finding creeps that need healing.



  • https://docs.screeps.com/api/#Room.find

    You may need to designate "type" as FIND_*.



  • Game.MY_CREEPS looks like a bug.

    Further you need to check if the creep to heal is in range.

    var ret = creep.heal(damagedCreeps[0]);
    if(ret === ERR_NOT_IN_RANGE) {
      creep.moveTo(damagedCreeps[0]);
    } else if( ret !== OK) {
      console.log("failed to heal:", damagedCreeps[0], ret);
    }
    


  • "ERR_OUT_OF_RANGE" does not exist. ERR_NOT_IN_RANGE??? https://docs.screeps.com/api/#Creep.heal


  • Dev Team

    @key2130 That's right there in the documentation: The target has to be at adjacent square to the creep.

    You need to check if your healer is next to the damaged creep (and move the healer towards the damaged creep if it's away)



  • @key2130 Yeah that's the correct error code I got it wrong. (updating the original).