Сначала я использовал один скрипт, все работало хорошо, я импортирую из объекта "роль". После этого я решил переделать скрипт и сформировать объект в al oop, и по какой-то причине он работает неправильно, хотя выглядит точно так же. В цикле подсчета он показывает правильное число, но вне него он показывает другое.
main. js
const rolesRoom = require('roles');
const createRoles = {}; // here I am creating a new object with which it does not work
for (const i in rolesRoom.rooms) {
createRoles[rolesRoom.rooms[i].name] = rolesRoom.levels[rolesRoom.rooms[i].level];
}
// const roles = createRoles; // if uncomment it will be new code
const roles = rolesRoom.role; // Here i import old code
// подсчитываем количество крипов в руме
for (const spawnRoom in roles) {
for (const roleName in roles[spawnRoom]) {
roles[spawnRoom][roleName].currentQuantity = _.sum(Game.creeps, (c) => {
return c.memory.role === roleName && c.memory.spawnRoom === spawnRoom;
});
if (spawnRoom === 'E59S58' && roleName === 'upgrader') {
console.log(roles['E59S58'].upgrader.currentQuantity)
// old code - 0
// new code - 0
// if here old code it will be 0, and if will be new code it will be 0
}
}
}
console.log(roles['E59S58'].upgrader.currentQuantity)
// old code - 0
// new code - 1 (why????????????)
// if here old code it will be 0, but if will be new code it will 1 why is this so ???
из этого файла я получаю данные
ролей. js
module.exports = {
rooms: [
{
name: 'E59S58',
level: 5
},
{
name: 'E58S58',
level: 5,
distantHarvester: {quantity: 2, goRoom: 'E58S57'}
},
{
name: 'E59S57',
level: 5,
distantHarvester: {quantity: 1, goRoom: 'E59S56'}
},
{
name: 'E57S57',
level: 5,
distantHarvester: {quantity: 1, goRoom: 'E57S56'}
}
],
levels: {
5: {
'getter': {
'quantity': 2,
'strength': [WORK, WORK, WORK, WORK, WORK, WORK, WORK, WORK, WORK, WORK, CARRY, CARRY, MOVE, MOVE, MOVE, MOVE]
},
'filler': {
'quantity': 1,
'strength': [CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE]
},
'harvester': {
'quantity': 1,
'strength': [WORK, CARRY, CARRY, MOVE, MOVE]
},
'bigHarvester': {
'strength': [WORK, WORK, WORK, WORK, WORK, WORK, WORK, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE]
},
'upgrader': {
'quantity': 1,
'strength': [WORK, WORK, WORK, WORK, WORK, WORK, WORK, WORK, WORK, WORK, CARRY, CARRY, MOVE, MOVE, MOVE, MOVE]
},
'repairer': {
'quantity': 1,
'strength': [WORK, WORK, WORK, WORK, WORK, WORK, WORK, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE]
},
'builder': {
'quantity': 0,
'strength': [WORK, WORK, WORK, WORK, WORK, WORK, WORK, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE]
},
'distantHarvester': {
'strength': [WORK, WORK, WORK, WORK, WORK, CARRY, CARRY, CARRY, CARRY, CARRY, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE]
},
'attacker': {
'quantity': 0,
'strength': [TOUGH, TOUGH, TOUGH, TOUGH, TOUGH, TOUGH, TOUGH, TOUGH, TOUGH, ATTACK, ATTACK, ATTACK, ATTACK, ATTACK, ATTACK, ATTACK, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE]
},
'claimer': {
'quantity': 0,
'strength': [CLAIM, MOVE, MOVE]
}
}
},
role: {
E59S58: {
'getter': {
'quantity': 2,
'strength': [WORK, WORK, WORK, WORK, WORK, WORK, WORK, WORK, WORK, WORK, CARRY, CARRY, MOVE, MOVE, MOVE, MOVE]
},
'filler': {
'quantity': 1,
'strength': [CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE]
},
'harvester': {
'quantity': 1,
'strength': [WORK, CARRY, CARRY, MOVE, MOVE]
},
'bigHarvester': {
'strength': [WORK, WORK, WORK, WORK, WORK, WORK, WORK, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE]
},
'upgrader': {
'quantity': 1,
'strength': [WORK, WORK, WORK, WORK, WORK, WORK, WORK, WORK, WORK, WORK, CARRY, CARRY, MOVE, MOVE, MOVE, MOVE]
},
'repairer': {
'quantity': 1,
'strength': [WORK, WORK, WORK, WORK, WORK, WORK, WORK, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE]
},
'builder': {
'quantity': 0,
'strength': [WORK, WORK, WORK, WORK, WORK, WORK, WORK, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE]
},
'distantHarvester': {
'strength': [WORK, WORK, WORK, WORK, WORK, CARRY, CARRY, CARRY, CARRY, CARRY, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE]
},
'attacker': {
'quantity': 0,
'strength': [TOUGH, TOUGH, TOUGH, TOUGH, TOUGH, TOUGH, TOUGH, TOUGH, TOUGH, ATTACK, ATTACK, ATTACK, ATTACK, ATTACK, ATTACK, ATTACK, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE]
},
'claimer': {
'quantity': 0,
'strength': [CLAIM, MOVE, MOVE]
}
},
E58S58: {
'getter': {
'quantity': 2,
'strength': [WORK, WORK, WORK, WORK, WORK, WORK, WORK, WORK, WORK, WORK, CARRY, CARRY, MOVE, MOVE, MOVE, MOVE]
},
'filler': {
'quantity': 1,
'strength': [CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE]
},
'harvester': {
'quantity': 1,
'strength': [WORK, CARRY, CARRY, MOVE, MOVE]
},
'bigHarvester': {
'strength': [WORK, WORK, WORK, WORK, WORK, WORK, WORK, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE]
},
'upgrader': {
'quantity': 1,
'strength': [WORK, WORK, WORK, WORK, WORK, WORK, WORK, WORK, WORK, WORK, CARRY, CARRY, MOVE, MOVE, MOVE, MOVE]
},
'repairer': {
'quantity': 1,
'strength': [WORK, WORK, WORK, WORK, WORK, WORK, WORK, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE]
},
'builder': {
'quantity': 0,
'strength': [WORK, WORK, WORK, WORK, WORK, WORK, WORK, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE]
},
'distantHarvester': {
'strength': [WORK, WORK, WORK, WORK, WORK, CARRY, CARRY, CARRY, CARRY, CARRY, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE]
},
'attacker': {
'quantity': 0,
'strength': [TOUGH, TOUGH, TOUGH, TOUGH, TOUGH, TOUGH, TOUGH, TOUGH, TOUGH, ATTACK, ATTACK, ATTACK, ATTACK, ATTACK, ATTACK, ATTACK, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE]
},
'claimer': {
'quantity': 0,
'strength': [CLAIM, MOVE, MOVE]
}
},
E59S57: {
'getter': {
'quantity': 2,
'strength': [WORK, WORK, WORK, WORK, WORK, WORK, WORK, WORK, WORK, WORK, CARRY, CARRY, MOVE, MOVE, MOVE, MOVE]
},
'filler': {
'quantity': 1,
'strength': [CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE]
},
'harvester': {
'quantity': 1,
'strength': [WORK, CARRY, CARRY, MOVE, MOVE]
},
'bigHarvester': {
'strength': [WORK, WORK, WORK, WORK, WORK, WORK, WORK, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE]
},
'upgrader': {
'quantity': 1,
'strength': [WORK, WORK, WORK, WORK, WORK, WORK, WORK, WORK, WORK, WORK, CARRY, CARRY, MOVE, MOVE, MOVE, MOVE]
},
'repairer': {
'quantity': 1,
'strength': [WORK, WORK, WORK, WORK, WORK, WORK, WORK, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE]
},
'builder': {
'quantity': 0,
'strength': [WORK, WORK, WORK, WORK, WORK, WORK, WORK, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE]
},
'distantHarvester': {
'strength': [WORK, WORK, WORK, WORK, WORK, CARRY, CARRY, CARRY, CARRY, CARRY, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE]
},
'attacker': {
'quantity': 0,
'strength': [TOUGH, TOUGH, TOUGH, TOUGH, TOUGH, TOUGH, TOUGH, TOUGH, TOUGH, ATTACK, ATTACK, ATTACK, ATTACK, ATTACK, ATTACK, ATTACK, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE]
},
'claimer': {
'quantity': 0,
'strength': [CLAIM, MOVE, MOVE]
}
},
E57S57: {
'getter': {
'quantity': 2,
'strength': [WORK, WORK, WORK, WORK, WORK, WORK, WORK, WORK, WORK, WORK, CARRY, CARRY, MOVE, MOVE, MOVE, MOVE]
},
'filler': {
'quantity': 1,
'strength': [CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE]
},
'harvester': {
'quantity': 1,
'strength': [WORK, CARRY, CARRY, MOVE, MOVE]
},
'bigHarvester': {
'strength': [WORK, WORK, WORK, WORK, WORK, WORK, WORK, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE]
},
'upgrader': {
'quantity': 1,
'strength': [WORK, WORK, WORK, WORK, WORK, WORK, WORK, WORK, WORK, WORK, CARRY, CARRY, MOVE, MOVE, MOVE, MOVE]
},
'repairer': {
'quantity': 1,
'strength': [WORK, WORK, WORK, WORK, WORK, WORK, WORK, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE]
},
'builder': {
'quantity': 0,
'strength': [WORK, WORK, WORK, WORK, WORK, WORK, WORK, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, CARRY, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE]
},
'distantHarvester': {
'strength': [WORK, WORK, WORK, WORK, WORK, CARRY, CARRY, CARRY, CARRY, CARRY, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE]
},
'attacker': {
'quantity': 0,
'strength': [TOUGH, TOUGH, TOUGH, TOUGH, TOUGH, TOUGH, TOUGH, TOUGH, TOUGH, ATTACK, ATTACK, ATTACK, ATTACK, ATTACK, ATTACK, ATTACK, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE]
},
'claimer': {
'quantity': 0,
'strength': [CLAIM, MOVE, MOVE]
}
}
}
};