1 Flag exists in 2 places.



  • Occasionally I create a flag in one room and then the following tick I change its position to a different room. This seems to SOMTIMES result in the following:

    • The original flag stays where it was created.
    • A second flag with the same name as the original is placed in the new position.
    • The entry in Game.flags points to the second flag in the new position.
    • BOTH the original flag and the second flag (with the same name) show up in the game, and are selectable in the interface. Restarting the client, refreshing the browser, etc does not get rid of the original flag.
    • BOTH flags (with the same name) are .findable with FIND_FLAGS, so it seems not to be only a display issue, the flag exists as a room object in 2 distinct rooms.

    Some console proof (also showing room names and shard if necessary):

    [Game.rooms.W22N11, Game.rooms.W21N12].forEach(r => console.log(r.find(FIND_FLAGS)))
    [4:38:36 PM][shard2][flag SCOUT_W22N11_FROM_W21N12]
    [4:38:36 PM][shard2][flag FILL_WAIT_W21N12],[flag SCOUT_W22N11_FROM_W21N12]
    

    Note that [flag SCOUT_W22N11_FROM_W21N12] exists in both rooms on the same tick.

    I have had this happen to me twice now in the last week or so, I do not create these flags often. The first time I thought it was just a UI glitch and I don't remember what I did. Perhaps I clicked on the flag that should not have been there and pressed "Remove Flag," but I can't say for sure what happened. I will be leaving the errant flag in existence for now just in case it can be of some use in finding or fixing the bug. Let me know if you would like any more information.


  • Culture

    I've seen this kind of issue before but thought it was my code that was causing it.
    I'd like to help you narrow it down to the events leading up to this bug.

    • Did you create a flag and lose vision on the same tick?

    I've had issues with creating flags myself ( Linky ) and I think they might be related



  • I have also seen this and have just been able to reproduce it.

    I placed a flag called test into a room I have vision of.

    Then added the following snippet to my code:

    Game.flags.test.setPosition(new RoomPosition(Game.time%10+20, 11, "W6S11"))

    to move the flag on every tick.

    When I select the flag in the GUI and choose to move it to a room I dont have vision of, the flag is duplicated.

    If I move the flag to a room I have vision over it seems to work as expected.



  • @Dissi I was creating the flag in an owned room on one tick, and then on the next tick moving it to a room with no vision. This scenario does not always cause the problem but seems to occasionally.

    @SteveTrov Thank you for this input, it led me to do some more testing with interesting results.

    I wrote the following code:

    let flagName = "test";
    let desiredPosition = new RoomPosition(25, 25, "W27N13"); // no vision of this room
    let creationPosition = new RoomPosition(6, 29, "W25N13"); // owned room with vision
    
    global.flagTest1 = function() {
        let flag = Game.flags[flagName];
        if (!flag) {
            creationPosition.createFlag(flagName);
        } else {
            flag.setPosition(desiredPosition);
        }
        log(`Flag exists: ${flag}`);
    };
    
    global.flagTest2 = function() {
        let flag = Game.flags[flagName];
        if (!flag) {
            creationPosition.createFlag(flagName);
        } else {
            flag.setPosition(Game.time % 2 === 0 ? creationPosition : desiredPosition);
        }
        log(`Flag exists: ${flag}`);
    };
    

    And performed the following tests:

    1. I put flagTest1(); at the top of my main loop while the flag was NOT in existence.
      • Result: A flag by the name "test" was created, and then proceeded to alternate in and out of existence at creationPosition, never making it to desiredPosition every other tick the log statement would say that the flag did not exist. I do not have any other code in my code base that would be removing this flag. Eventually after some number of ticks (perhaps a dozen or two) the flag successfully moved to desiredLocation and stayed there, behaving as you would expect.
    2. I replaced flagTest1(); with flagTest2(); at the top of my main loop. The flag was already in existence.
      • Result: The flag "moved" to desiredPosition but also remained at creationPosition. There are now two instances of the flag that are both clickable and selectable in the UI.

    I have repeated both of these tests multiple times with similar results.

    Another interesting note: While the flag is "duplicated" and exists in both rooms, calling Game.flags.test.remove() returns OK but neither flag is removed. Both stay in existence after repeated calls to .remove() from the console. After clicking one of the flags in the UI and pressing the UI button to remove the flag, it is removed but the other version of it stays in existence and calling .remove() now functions properly on the remaining flag.