Help with eserving multiple rooms - creep.reserveController



  • Hey guys, I'm having trouble with my reserver creep, which is supposed to move to a target room and then reserve the controller in that room. Currently, it gets to the target room, and then it switches back to the romm before that, and then it keeps switching.

    This is my code for the reserver unit:

     

    var roleReserver = {
    /** @param {Creep} creep **/
    run: function(creep) {
    //MOVE TO TARGET ROOM
    if(creep.room != 'E44S19') {
    var route = Game.map.findRoute(creep.room, 'E44S19');
    if(route.length > 0) {
    var exit = creep.pos.findClosestByRange(route[0].exit);
    creep.moveTo(exit);
    }
    }
    //RESERVE CONTROLLER IN TARGET ROOM (NOT WORKING, CREEP IS SWITCHING BETWEEN TARGET ROM AND THE ONE BEFORE THAT)
    else {
    if(creep.room.controller) {
    if(creep.reserveController(creep.room.controller) == ERR_NOT_IN_RANGE) {
    creep.moveTo(creep.room.controller);
    }
    }
    }
    }
    }
    module.exports = roleReserver;

     

    I think the Problem is either, it can't get the controller because I don't own the room, or, the creep doesn't actually get the order to move to the controller for some reason. I have noticed, that in creep.reserveController(creep.room.controller); the reserveController part doesn't actually markup in yellow, so I'm not sure if it's working, but I copy/pasted it from the dpcumentation, so... any help? Basically what I want is be able to tell it which room to reserve when it's spawned, so it's easy to use for multiple rooms.

     

    Thanks in advance for your answers 😃

     

    Edit: I got it to work now, but reserveController is still not yellow O_o, Maybe move to bug forum? or is it a local problem with the markup? I didn't change anything for that



  • that is the usual hardship of multi-room travel. an idle creep doing nothing at a room edge will bounce back and forth between rooms each tick.

    the simplest answer for traveling is to use RoomPosition and MoveTo. This example will not have that issue with moving. 

     

    let a = new RoomPosition(25,25,'sim');
    creep.moveTo(a);