creep.room.name not being updated correctly



  • I am attempting to setup a room claiming system in my private server but I am running into problems due to issues with the room parameter of creeps. For whatever reason it is not being updated every tick and so causes faulty behaviors when using it for comparisons against the room name it is actually in.

    Here is some console output as an example and the code generating that output:

    W8N3 W7N3

    console.log(creep.room.name + " " + creep.memory.targRm);

    The above console statement is called every tick as I have it in my claimer code. When the claimer appears in the room to be claimed (W7N3) the room.name param claims that the creep is still in my starting room (W8N3). It then retreats back into the starting room and then back into the room to be claimed until it dies. Here is my code (based off of thPion's):

    var roleClaimer = {
    
        /** @param {Creep} creep **/
        run: function (creep) {
            console.log(creep.room.name + "  " + creep.memory.targRm);
            if (creep.room.name != creep.memory.targRm) {
                var exit = creep.room.findExitTo(creep.memory.targRm);
    
                creep.moveTo(creep.pos.findClosestByRange(exit));
            } else {
                var res = creep.claimController(creep.room.controller);
                if (res == ERR_NOT_IN_RANGE) {
                    creep.moveTo(creep.room.controller);
                } else if (res == ERR_GCL_NOT_ENOUGH) {
                    console.log('GCL too low');
                }
            }
        }
    };
    
    module.exports = roleClaimer;
    

    The code is simple and seems like it should just work but it doesn't. Am I missing something or is something broken?



  • I suspect that you have encountered the same issue with path finding as many before you. The creep bounce back and forth between rooms because the moveTo action returns "ERR_NO_PATH" the first tick in the new room.

    https://screeps.com/forum/topic/1352/err_no_path-when-creep-moveto-flag-in-another-room/16



  • @sandgrainone said in creep.room.name not being updated correctly:

    I suspect that you have encountered the same issue with path finding as many before you. The creep bounce back and forth between rooms because the moveTo action returns "ERR_NO_PATH" the first tick in the new room.

    https://screeps.com/forum/topic/1352/err_no_path-when-creep-moveto-flag-in-another-room/16

    Exactly that. I had to make my screeps go to a random point in the room before attempting to path to the controller. That seems to be the only way to keep them from playing musical rooms. Will post the code below in case someone else runs into the problem and many of the alternatives don't work for them either:

    if (creep.room.name != creep.room.targRm) {
            // create position in the middle of target room; game was not properly reading memory so manually assigned room name
            var targetPos = new RoomPosition(25, 25, 'W7N3'); 
            creep.moveTo(targetPos);
        } else {
            var res = creep.claimController(creep.room.controller);
            if (res == ERR_NOT_IN_RANGE) {
                creep.moveTo(creep.room.controller);
            } else if (res == ERR_GCL_NOT_ENOUGH) {
                console.log('GCL too low');
            } else {
                console.log(res);
            }
        }