Problem with accessing memory of new Flag



  • So I've been playing this game since yesterday, and tried to make my harvester code more intelligent using flags, placed on the sources (to store information).

    However, something goes wrong when I try to access the flags memory, because they behave as if they do not exist. (source refers to the corresponding source (this works, as it places the flag at the right spot)

    var title = Game.spawns.Spawn1.room.createFlag(source.pos);
    console.log('Making Flag: ' + title); //Prints: Making Flag: Flag1

    Game.flags[title].memory.spots = 3; //Here is the error

    To at the last line it goes wrong and I cannot seem to get it fixed (I'm not experienced in programming, so it might be very obvious.



  • not sure right now  and can't try, but most likely it's the same kind of behaviour as with new creeps: they only start to exist the next tick. 

    However, if you change the line:

    Game.flags[title].memory.spots = 3;

    to

    Memory.flags[title].spots = 3;

    it should work, because you are accessing Memory directly, without the need for the flag to exist. Just as with creeps, memory is not directly tied to them, and can exist without the flag/creep existing; the Flag.memory property is just a shortcut.