Memory.creeps have no names?



  • Not sure what is going on here but when I try to iterate through my creeps in memory I an unable to do anything useful with them... i.e. access their memory and what not.

    Any ideas?

     

    var memCreeps = Memory.creeps;
    console.log(JSON.stringify(memCreeps)); //outputs as expected


    for (var deadCreep in memCreeps)

    {
    console.log("Creep: " + memCreeps[deadCreep].name); //outputs "Creep: undefined
    var spawn = Game.getObjectById(memCreeps[deadCreep].homeSpawnID);
    console.log(spawn.name); //Throws an error
    }



  • Well, `memCreeps[deadCreep] != Game.creeps[deadCreep]`. 

    Are you storing a property .name in your creep's memory? If not, then `memCreeps[deadCreep].name === undefined`. 

    Unsure about your spawn. You may want to log homeSpawnID as well...



  • Ah! Thanks, I think I figured it out... correct me if Im wrong. The .name is a property of the creep instance. Which is not what is stored in memory. So when I call memCreeps[deadCreep].name Im attempting to access the .name property of the of the creep's memory instead of the creep instance. Which will obviously error because the creep's memory doesnt contain a name property.



  • Memory.creeps(creepName)

    Object.keys(Memory.creeps);

    the name is your hash key. having a .name tag as well would be somewhat redundant.