Skip to content

Commit 9233bf0

Browse files
committed
fix bug for data be undefined(when you get killed out and respawn in a new room.)
1 parent a1624a1 commit 9233bf0

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/brain_memory.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,17 @@ brain.addToStats = function(name) {
3434
};
3535

3636
brain.handleUnexpectedDeadCreeps = function(name, creepMemory) {
37-
let data = {};
37+
let data = undefined;
3838
if (creepMemory.room) {
3939
data = global.data.rooms[creepMemory.room];
4040
} else {
4141
console.log(`${Game.time} ${name} handleUnexpectedDeadCreeps no creepMemory.room creepMemory: ${JSON.stringify(creepMemory)} data: ${JSON.stringify(global.data.creeps[name])}`);
4242
}
4343

44+
if (!data) {
45+
data = {};
46+
}
47+
4448
debugLog(`${Game.time} ${creepMemory.room} ${name} memory hostile: ${data.hostileCreepCount}`);
4549
if (data.hostileCreepCount > 0) {
4650
debugLog('brain', `${creepMemory.room} ${name} Not in Game.creeps with hostiles lived ${Game.time - creepMemory.born} hostiles: ${data.hostileCreepCount} - I guess killed by hostile`); // eslint-disable-line max-len

0 commit comments

Comments
 (0)