Finding stuff across rooms



  • I want a harvester to find the closest source, regardless of what room it's in. findclosestbyrange only returns sources in the same room. Is there any way to pathfind between rooms?

    Clearly creeps can path between rooms find; but generating based on these paths doesn't seem possible. Is there a workaround?



  • Rooms you dont have vision of you cant access via the room object. You can use flags to bypass some of these limitations, or you can have scout units stand in these rooms to give you vision.

    Here's some code for moving between rooms you don't have vision of

    //If not in the correct room, move towards it
    if(creep.room.name != sourceRoom)
    {
    var exitDir = Game.map.findExit(creep.room.name, sourceRoom);
    var Exit = creep.pos.findClosestByPath(exitDir);
    creep.moveTo(Exit);
    }