I haven't found any way to assign hooks to anything, and if I could it would be very useful. Also, how can I check whether a game object still exists? (i.e. hasn't died of age, and wasn't destroyed by an enemy.)
If you mean via API - not possible yet. But you can change your current state and compare it to memorized previous state of the objects. For example, if some creep name in Memory
still presents, but it is gone in Game.creeps
, then something happened.
for(var i in Game.creeps) {
var creep = Game.creeps[i];
creep.memory.lastSeenAt = {x: creep.pos.x, y: creep.pos.y};
}
for(var i in Memory.creeps) {
if(!Game.creeps[i]) {
console.log("Oops! Something happened with a creep "+creep.name+" at "+
Memory.creeps[i].lastSeenAt.x+","+Memory.creeps[i].lastSeenAt.y);
}
}
Here is my use case :
After a while, when using the Room.find(Game.MY_CREEPS)
, I'll get dead guards aswell. Having to filter them all the time is really painfull, and the global Memory
continues to list them. Is there a way to remove dead creeps from the global Memory
object ?
[EDIT] Found this, hope it will help.
for(var i in Memory.creeps) {
if(!Game.creeps[i]) {
delete Memory.creeps[i];
}
}
I run it at the beginning of each tick
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With