@mrfaul no it doesn't work )))))))))))))))) https://pastebin.com/AgCJZ4y6
Posts made by kepamuk
-
RE: Two same objects show different result
-
RE: Two same objects show different result
@mrfaul I started to count differently and the problem is the same, with the old way everything is fine, with the new problem)))))))) can say why?)))))
const createRoles = {}; for (const i in rolesRoom.rooms) { createRoles[rolesRoom.rooms[i].name] = rolesRoom.levels[rolesRoom.rooms[i].level]; } const roles = createRoles; // const roles = rolesRoom.role; // console.log(JSON.stringify(roles)) // подсчитываем количество крипов в руме for (const spawnRoom in roles) { for (const roleName in roles[spawnRoom]) { roles[spawnRoom][roleName].currentQuantity = 0; } } for (const i in Game.creeps) { const creep = Game.creeps[i]; roles[creep.memory.spawnRoom][creep.memory.role].currentQuantity += 1; if (creep.memory.spawnRoom === 'E59S58' && creep.memory.role === 'upgrader') { // console.log(creep.memory.spawnRoom) // console.log(creep.memory.role) console.log(creep) // we only come here once } } console.log(roles['E59S58']['upgrader'].currentQuantity) // here 4 why ?????????????
-
RE: Two same objects show different result
@mrfaul ok then i try to change my code ! thank you
-
RE: Two same objects show different result
@smokeman here you can see the objects are completely identical, but show different results
I was thinking if you have the opportunity, maybe you could look with teamviawer?
-
RE: Two same objects show different result
@smokeman said in Two same objects show different result:
Meaning roleRoom.rooms is an array, not an object. Sure, the overall container it's in is an object... but rooms is an array. So you use the of iterator, like: for (const i of rolesRoom.rooms)
I did so and the result is the same
for (const obj of rolesRoom.rooms) { createRoles[obj.name] = rolesRoom.levels[obj.level]; }
To be honest? I could feel myself descending into madness just trying to figure out what that code does. It could probably be a lot simpler. Not that I'm judging... I've certainly written code I've looked at later and wondered what was going on.
sorry but I'm just learning)) I think it's better than nothing
-
RE: Two same objects show different result
@mrfaul said in Two same objects show different result:
"But are you sure you don't have any creeps that get counted?";
of course there are no creeps you see in cycle 0 itself, but when outside the cycle this field shows 1
-
RE: Two same objects show different result
@mrfaul I tried but still did not understand how to highlight the code
-
Two same objects show different result
At first I used one script, everything worked well, I import from the "role" object. After that I decided to redo the script and form the object in a loop, and for some reason it does not work correctly, although it looks exactly the same. Inside the counting cycle it shows the correct number, but outside it it shows another.
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 ???
from this file I get data
roles.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] } } } };