Two same objects show different result



  • @mrfaul Here: alt text

    When I comment this "console.log("Test for creep: ",c.name," is ",toString(test)); "

    alt text



  • @smokeman alt text 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?



  • It is quite obvious that something isn't working, object Undefined isn't a option, it should be either true or false.
    This means the boolian check above fails, replace the log with this one:

    console.log("role: ",c.memory.role," spawn: ", c.memory.spawnRoom," test: ",toString(test));
    

    But honestly the way you are counting your creeps is very very inefficient.
    You are iterating for each role in each room through your entire rooster of creeps: rooms * roles * creeps = CPU waste
    You should instead iterate through your creeps once and count what they do in a fresh temporary object and use that to update your roles,
    or better leave that temporary since it is a snapshot of the current tick anyway don't bother to save that.



  • @mrfaul ok then i try to change my code ! thank you



  • @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?)))))

    alt text

    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 ?????????????


  • alt text alt text



  • You might want to check if your room/role combination is valid and don't blindly trust the incremental operators, sometimes they behave wired for no apparent reason:

    if( roles[creep.memory.spawnRoom] && roles[creep.memory.spawnRoom][creep.memory.role] ){
    roles[creep.memory.spawnRoom][creep.memory.role].currentQuantity = 
    roles[creep.memory.spawnRoom][creep.memory.role].currentQuantity + 1;
    }
    

    But if that still dosn't work please dump your entire main somewhere like pastbin etc.



  • @mrfaul no it doesn't work )))))))))))))))) https://pastebin.com/AgCJZ4y6



  • Sorry for the late answser I was busy

    hmm indeed I see nothing in there why it shouldn't work, but I have a idea why it could be buggy:
    You only set the roles quantity to "0" but that doesn't guaranties that there are no wild "undefined" variables when you loop through your creeps.

    Try this:

    for (const i in Game.creeps) {
            const creep = Game.creeps[i];
            let currentQuantity = roles[creep.memory.spawnRoom][creep.memory.role].currentQuantity || 0; // use the saved variable or "0"
            ++currentQuantity; // increment
            roles[creep.memory.spawnRoom][creep.memory.role].currentQuantity = currentQuantity; // save
    
            if (creep.memory.spawnRoom === 'E59S58' && creep.memory.role === 'upgrader') {
                 console.log(roles['E59S58']['upgrader'].currentQuantity)
            }
        }
    

    Using this method you can also get rid of the additional for loop that only sets it to zero.
    One thing less that takes up time.



  • @kepamuk @o4kapuk jo apparently the last picture:

    http://dl4.joxi.net/drive/2020/01/31/0011/2711/772759/59/69625b05ca.jpg

    Is contaminated with some malicious software and got flagged by our GData Enterprise Suite... So it could be that the host server or your private machine is compromised pls check that.

    Update: Or GData is just beeing GData 😑 since I double checked it and only 2 out of 73 scanner flagged it.
    Man that software is annoying, but better than nothing. At least it is doing it's job... sorta.