Flag Bugs.



  • Hi,

    I did the tests below to see what you can do with flags. It seems like you can do only 1 intent per flag per tick, you can create, but you cannot change the colors/posistion after. The next tick you can only change color or position. Below I've added the code I tested with and the various changes I did to recreate the issues. These were done with the room Object seen, I can do additional tests with out room object.

    Test environment

    Shard2 created a flag named test - color white/white. This is the function I tested with. Moving and commenting out parts I don't need.

    function testFlagFunction() { if(Game.flags.test === undefined) return; let testFlag = Game.flags.test; var testPos = new RoomPosition(25,25,'E19S49'); var testPos2 = new RoomPosition(20,20,'E19S49'); // console.log("remove", testFlag.remove() ); console.log("setPos",testFlag.setPosition(testPos)); console.log("setColor", testFlag.setColor(COLOR_WHITE,COLOR_WHITE) ); }

    First test is just make sure all the functions work alone as intended.

    1. Remove() --- Success - Returned OK.
    2. setColor --- Success - Returned OK
      • Can move flag location manually.
      • Cannot change flag color manually.
    3. setPosistion() --- Success - Returned OK
      • Cannot change flag location - but visuals I have programmed do show up in the location I'm trying to move to.
      • Can change color Manually.

    Not having vision in the room.

    1. Remove() --- Returned OK X(random) times before it succesfuly removed, sometimes 3 ticks, sometimes 20 ticks.
    2. setColor --- Returned OK - Never changed Colors.
      • Can move flag location manually.
      • Can change flag color manually.
    3. setPosistion() --- Returned OK - Never changed Posistion.
      • Can Change Flag pos
      • Can change color Manually.

    2nd series of test will now be a combination of commands.

    1. setColor then remove()
      • Expected Behavor should be the flag is removed.
      • Both come back 0 - or OK
      • Flag color changes -
      • Flag does not get removed.
    2. SetPos then Remove()
      • Expected behavor is that the flag should be removed.
      • Both come back 0 - or Ok.
      • Flag changes pos.
      • Flag doesn't get removed.
    3. SetColor then setPosistion()
      • Expected Behavor should be change in color and posistion.
      • Both come back 0 or OK
      • Flag changes color
      • Flag does not change location.
    4. Remove() then setColor
      • Expected behavor is error code due to setColor
      • Both come back 0.
      • Remove doesn't go into effect.
      • SetColor works changing flag color.
    5. Remove() then setPosistion()
      • Expected Behavior is error code due to flag being removed.
      • Both commands come back 0
      • Remove doesn't go in effect.
      • Flag does change location.
    6. SetPosistion then SetColor()
      • Expected Behavior is that it changes color and location.
      • BOth commands come back 0
      • Setposistion does work
      • Flag color doesn't change.

    Same commands, but with out room vision/object.

    1. setColor then remove()
      • Expected Behavor should be the flag is removed.
      • Both come back 0 - or OK
      • No color change or remove done.
    2. setPos then remove()
      • Expected Behavor should be the flag is removed.
      • Both come back 0 - or OK
      • No pos change or remove done.
    3. SetColor then setPosistion()
      • Expected Behavor should be change in color and posistion.
      • Both come back 0 or OK
      • NO color or pos changes.
    4. Remove() then setColor
      • Expected behavor is error code due to setColor
      • Both come back 0.
      • No remove or SetColor
    5. Remove() then setPosistion()
      • Expected Behavior is error code due to flag being removed.
      • Both commands come back 0
      • No remove or setPos
    6. SetPosistion then SetColor()
      • Expected Behavior is that it changes color and location.
      • BOth commands come back 0
      • no pos or color change.

    CreateFlag test

    1. Testing it alone.
      • Returned 'test'
      • Flag created.
    2. Testing it with setPosistion
      • Returned 'test'
      • Returned setPosistion 0
      • Flag Created.
      • No change in posistion.
    3. Testing it with setColor.
      • Returned 'test'
      • Retuned Setcolor 0
      • Flag Created.
      • No change in color.
    4. Testing it with remove.
      • returned 'test'
      • Flag Created.
      • returned 0 for remove
    5. Flag exists, doing createFlag then setPosistion
      • Returned -3 for the flagCreation
      • setPosistion Does work and returned 0. . Flag exists, doing createFlag then setColor
      • Returned -3 for the flagCreation
      • setColor Does work and returned 0.

    Below is the function I used to test CreatFlag.

    function testFlagFunction() { var testPos = new RoomPosition(25,25,'E19S49'); var testPos2 = new RoomPosition(20,20,'E19S49'); if(Game.flags.test === undefined){ console.log('create', Game.rooms.E19S49.createFlag(25, 25, 'test') ); let testFlag = Game.flags.test; // console.log("setColor", testFlag.setColor(COLOR_YELLOW,COLOR_WHITE) ); // console.log("setPos",testFlag.setPosition(testPos2)); console.log("remove", testFlag.remove() ); }

    }

    :ok_hand:


  • Hey likeafox,

    Thank you for the report. The issue is queued for investigation and fixing.



  • It gets really fun when you place a flag by hand in a room that has no active entities in it (enemy or friendly creeps). The flag gets added to your Game.flags object but you can't modify it in the code, which means if you try to change the color it fails to actually change the color even though setColor returns 0.



  • Programmatically creating flags is, to me, one of the most inconsistent and frustrating experiences in the game, and I think it should be a high priority issue to work on. Here are my biggest issues I have with how flags are handled.

    You cannot create flags in rooms you don't have vision in. This would be understandable if the only way to create a flag was room.createFlag(pos), since the room object needs to be defined to call createFlag, but you can also call new RoomPosition(x,y,roomName).createFlag(). Room positions can be defined without vision of the room they are in, so you would expect that this would be a valid way to place a flag, especially since there is no return code on createFlag such as ERR_NO_VISION.

    However, you can create flags in a room you have vision and then move them to a new position where you lack vision, although this works very inconsistently as @likeafox has mentioned. If we ignore the inconsistencies with this, the natural way to place a flag where you lack vision would be to place it in a room with vision and set a memory property, say moveFlagTo, and move it on the next tick.

    But you can't easily do this either, because unlike creating a creep with spawn.spawnCreep, you cannot specify the initial memory of a flag. There are, of course, workarounds to this, but given that flags are one of the first game mechanics that new players encounter, it seems like a good idea to make them as easy as possible to work with.

    What makes this even more frustrating is that you can do all of these operations manually in the GUI without issue. I'm not as much of an automation purist as some others, and I don't want to kick the "everything should be automatable" horse, but flags are a pretty integral part of the game and act as a very natural attachment point for processes in your code. Since they are such an important and frequently used part of the game, I definitely think that you should be able to do any operation with flags programmatically which you can do manually.

    If I may be presumptuous enough to suggest the way that I would refactor flag creation:

    • Remove the Room.createFlag(pos) method and only allow flags to be created from RoomPosition
    • Ideally, allow flags to be placed at room positions without vision. If there is some compelling technical reason this can't be done, add ERR_NO_VISION as a return code option
    • Allow the user to specify a memory object for the flag to have upon creation (this is already easy enough to do - cache the object in Memory.temp.flagMemories[flagName] and move the object to flag memory at the beginning of the next tick - but it would be great to have this natively supported to be consistent with the way creep memories are initialized)
    • Change the function to accept an object with named properties, similar to the recent changes with StructureSpawn.spawnCreep()

    A refactored function signature could then look like: RoomPosition.createFlag(opts?: {name?: string, color?: string, secondaryColor?: string = color, memory?: any})

    Just my two cents.



  • @muon said in Flag Bugs.:

    However, you can create flags in a room you have vision and then move them to a new position where you lack vision, although this works very inconsistently as @likeafox has mentioned.

    The problem is very straightforward. The server doesn't simulate rooms with no active objects. When flags were moved from being objects to serialized assets (some time ago...) they no longer forced the server to simulate that room. Creating a construction site, using an observer to observe the room, or using some other mechanism to make the server acknowledge the existence of that room will make the flags in it visible to your code. Until this is done, any actions done on the flag "object" (which is only generated when the server recognizes the room from real objects and deserializes the flag data) will not be processed because, like I just said, the object doesn't really exist.

    This isn't to say that the [Flag NAME] object doesn't exist, just that any modifications done to it are not processed.


 

Looks like your connection to Screeps Forum was lost, please wait while we try to reconnect.