findClosestByPath returns an object, but can't find the path



  • As the title suggests, a creep can find the object closest by path, but can't find the path to the object?

    Context is a creep just entering a new room, and looking for a source to harvest. I refactored the code to find the error, so don't think about the specifics too much.

    Relevant code:

    0_1638747328331_screeps.PNG

    I don't understand how creep.pos.findClosestByPath can return an instance of an object, but creep.moveTo(object) can't find a path.

    The relevant room; creep position drawn in red

    0_1638748673850_room.PNG



  • You have to specify the creep to move to creep.moveTo(source[0]) instead of just creep.moveTo(source).

    👎


  • Looks like Marvin was helping you out on the discord, so assume that's the same challange you were having.

    @Tobyers findClosestByPath returns one object from a find constant search or an array of objects, whatever object is closest by all resulting paths searched to all objects. Your likely thinking of room.find() which returns an array, which then you have to pick one object from it.



  • Yeah, I don't really know what I was thinking it was 😕