• I am getting an error:
    if (creep.memory.role == "miner") {
    ^TypeError: Cannot read property 'role' of undefined
    at main:20:25

    I recently expanded to a new room and I am trying to adapt my code to work with two rooms.
    However, I am running into issues.
    THis is my code in main:

    for (var spawnName in Game.spawns) {
        var spawn = Game.spawns[spawnName];
        var creeps = _(Game.creeps).filter({
            memory: {
    for (var name in creeps) {
        console.log("name " + name);
        var creep = Game.creeps[name];
        if (creep === undefined) {
        if (creep.memory.role == "miner") {
            cm.harvest(creep, spawn);
        } else if (creep.memory.role == "builder") {
  , spawn);
        } else if (creep.memory.role == "runner") {
            cm.transfer(creep, spawn);
        } else if (creep.memory.role == "struct") {
  , spawn);
        } else {

    When I create a creep I set in its memory 'room' to equal the room's name that the spawnpoint which created the creep is in.

    That way I can keep track of my creeps by the room.

    So, I get the list of all creeps (Game.creeps), and filter it (with lodash) by 'memory: { room: "roomname" } So, it should return only the creeps within the room of the current spawn.

    However, when i then assign the creep to a variable and try to use it. I get all sorts of errors.

    Like, when I try to print the name of the creep I got all sort of weird messages instead like "___constructor___"

    Any idea what I am doing wrong?

  • var creeps = _(Game.creeps).filter({
    memory: {
    I am pretty sure that this already gives you a list of Creep objects, not their names