comparing pos not working
-
Hi guys,
Is there some sort of issue when comparing tow positions or is there a special way to do it?
Code snippet:
if(creep.pos != Game.flags[creep.memory.Source.name].pos)
{
console.log(creep.pos, Game.flags[creep.memory.Source.name].pos, creep.pos == Game.flags[creep.memory.Source.name].pos);
creep.moveTo(Game.flags[creep.memory.Source.name]);
}Console output:
[room E31S13 pos 18,22] [room E31S13 pos 18,22] false
How come the two positions don't equal each other?
Thanks,
Primoz
-
They are objects. Don't compare objects, compare properties / primitives. Or use the method in RoomPosition (don't know name right now, just read the docs...)
-
here, this is what you are looking for:
http://support.screeps.com/hc/en-us/articles/203079201-RoomPosition#isEqualTo
if(creep.pos.isEqualTo(Game.flags[creep.memory.Source.name].pos)) { ... }
-
thank you