maybe bug in findClosestByPath and findClosestByRange



  • Room W25S21. I call
    var exits = Game.map.describeExits(pos.roomName);
    console.log(JSON.stringify(exits));
    gives {"1":"W25S20","5":"W25S22","7":"W26S21"}

    There is a energy source 55db3189efa8e3fe66e04b78 at (5,10). When I do
    pos = new RoomPosition(5,10,"W25S21");
    result1 = pos.findClosestByPath(exits[7]);
    result2 = pos.findClosestByRange(exits[7]);
    console.log("path result", result1, "range result", result2);
    gives null null

    I might be confused, but there might be a bug here also.



  • Those functions expect an array of either RoomPosition or RoomObject objects as an argument, you are passing in a string ("W26S21").

    Instead of using describeExits and passing that to findClosestByPath, you could try using [Room.find](http://support.screeps.com/hc/en-us/articles/203079011-Room#find) with the FIND_EXIT_TOP, FIND_EXIT_BOTTOM etc as the first parameter which should give you all the exit tiles in that particular direction, and then passing the result of the find to findClosestByPath.



  •  

    Thanks for your help.

    findClosestByPath takes either a number or array. The number parameter is a FIND_?? constant. From API reference I am passing one of

    FIND_EXIT_TOP: 1,
    FIND_EXIT_RIGHT: 3,
    FIND_EXIT_BOTTOM: 5,
    FIND_EXIT_LEFT: 7,

    I am actually scouting a source in a remote room to see if it is economic to harvest so I do not necessarily have access to a room object. In fact, here I am creating a function to calculate the exact distance between any two points. Hence I really want to only use RoomPosition and Map methods.

    The code works mostly but for this one source object, both findClosestByPath and findClosestByRange seem to be failing. Ok, I will spend some more time debugging the code and maybe the problem will go away.