Check if path exists



  • I've had times where I need to check if a path from point A to point B exists. I decided to try a little hack with RoomPosition.findClosest().

    RoomPosition.prototype.hasPathTo = function(target, opts){
        return this.isNearTo(target) || this.findClosest([target], opts);
    };
    

    Works like a charm, because .findClosest() returns null if no path is found.