In PVE mode my



  • Guards I create always go for the two red dots at the top center.
    I have them set to attack Game.creeps.guard1.room.find(FIND_HOSTILE_CREEPS);
    I store this in a variable and then I use it as a target target[0] for my guards to fight. However I don't think I fully understand how the find array works. Does [0] not give me to closest enemy objects but something else?

    A brief explanation of what find returns might suffice.



  • room.find doesn't know creep position so it can't return closest. It returns array of all object of specified type.

    If you want closest hostile creep, then use

    creep.pos.findClosest(FIND_HOSTILE_CREEPS)
    

    You can also filter hostile creeps to exclude source keepers. Something like

    room.find(FIND_HOSTILE_CREEPS, {
        filter:function(enemy){enemy.owner.username !== 'Source Keeper'}
    })