screeps / engine

ISC License
133 stars 66 forks source link

[BUG Report] 'PowerCreep.ticksToLive' returns broken 'null' value on an unsapwned power-creep #144

Open HerrKai opened 1 month ago

HerrKai commented 1 month ago

When a power-creep is not spawned in, it's ticksToLive property returns null, however, this value is somehow broken. While it does show up correctly when saved to memory or logged to the console, it somehow causes an evaluation against null to be false. Example:

var powerCreep = Game.powerCreeps[Object.keys(Game.powerCreeps)[0]];
console.log("---before---");
console.log(powerCreep.ticksToLive)
console.log(powerCreep.ticksToLive == null)
console.log("---after---");

This will yield the following output:

[19:43:02][shard1]---before---
[19:43:02][shard1]null
[19:43:02][shard1]false
[19:43:02][shard1]---after---

The expected behaviour would be Game.powerCreeps[Object.keys(Game.powerCreeps)[0]].ticksToLive == null to be true in the case of Game.powerCreeps[Object.keys(Game.powerCreeps)[0]].ticksToLive being null. I've also checked and in this case the value is NOT a string that just sais "null".

I don't know a fix for this, however someone in discord suggested this was the cause: https://github.com/screeps/engine/blob/97c9d12385fed686655c13b09f5f2457dd83a2bf/src/game/power-creeps.js#L72

The start of this conversation in the official discord can be found with this link: https://discord.com/channels/860665589738635336/866441713383637032/1267538335002529853