Actual hit points of creeps not accessible. findClosest fails too.



  • The following code, that used to run correctly, suddenly stopped working.

    var MDId = 0;

    for(var cName in Game.creeps)
    {
    var c = Game.creeps[cName];

    console.log(cName, c.hits, c.hitsMax);
    
    if(c.memory.role == "medic")
    {
        var Patient = c.pos.findClosest(FIND_MY_CREEPS, {filter: function(object) {return object.hits < object.hitsMax; }});
    
        if(Patient) {
            c.moveTo(Patient);
            c.heal(Patient);
        } else {
            if(c.pos.getRangeTo(Spawns[0]) > 3) c.moveTo(Spawns[0]); 
        };
    
        MDId++;
    };
    

    }

    Specifically, Patient results to be null even if there are accessible damaged creeps. The previous print function prints full hit points even for damaged creeps. I'm running the code into the simulation room.



  • My bad, I found out that I had overwritten the "hits" property previously to the execution of this code. Can this be prevented by making the "hits" property read-only?