filter on findClosestByPath doesn't work as intended?



  • My repair creeps don't want to move on from ramparts they've fully 'repaired' on to walls that haven't been repaired yet. My logic calls for looking for a structure that has less than the max hit points using findClosestByPath with a filter.
     
    I've distilled the problem to the following two console calls:
     
    var r = Game.creeps.Anthony.pos.findClosestByPath(FIND_MY_STRUCTURES, (structure)=>{return (structure.hits < structure.hitsMax)})
    undefined
     
    r.hits < r.hitsMax
    false
     
    I'd expect the second call to return true, because of how it's the same exact logic as the filter!
     
    Is this some kind of nasty javascript scoping issue? I don't seem to have any stray global variables interfering that I can tell.
    Similar filtering seems to work fine for delivering energy to multiple sources (spawner, extensions, ...)


  • Erm. It also doesn't work if I make the function call correctly:

    r = Game.creeps.Anthony.room.find(FIND_MY_STRUCTURES, {filter:(s)=>{return (s.hits < s.hitsMax);}})
     
    (which is the way I'm doing it in my actual code, anyway)
     
    Since I'm making the calls so closely to each other, I don't think that it's a matter of the rampart degenerating and being repaired in between calls.


  • ... Further fiddling suggests that the filter function *does* always resolve as true right before I try to assign the job to the screep; so perhaps this is a problem with ramparts specifically fluctuating between full/not full, after all.



  • Wall, road and containers are structures that don't have owner. So you cannot find it with FIND_MY_STRUCTURES. You should use FIND_STRUCTURES for these buildings.



  • (edit: ignore me)