Memory no longer being saved with created Creep!



  • The following code no longer creates a creep with memory properties. This just started to happen yesterday 5/16/2015.

    var memory = {};
    memory['role'] = 'miner';
    memory['attacking'] = null;
    
    spawnName.createCreep([MOVE, WORK, WORK, WORK, WORK], null, memory);
    


  • This is working fine for me, only difference is that I do have a name set, also spawn is a spawn object.

    var rslt = spawn.createCreep(body, name, {
        roleGroups: setup.roleGroups,
        role: setup.role,
        isArcher: !!setup.isArcher,
        isHealer: !!setup.isHealer
    });
    


  • After further investigation, it looks like my cleanup creep code is now the one causing the issues I was having. Weird, it seems this worked the other day .... ?

    if (spawnName.spawning === undefined || spawnName.spawning === null) {
            for (var name in Memory.creeps) {
                var memoryCreep = Memory.creeps[name];
                if (!Game.creeps[name])
                    delete Memory.creeps[name];
            }
        }
    


  • Never ran into the need for this myself. Is it a big issue on the server-side version?

    I take it your investigation included completely removing the problematic bit of code from execution?
    Try comparing to undefined instead, like so:

    for (var name in Memory.creeps) {
        if (Game.creeps[name] === undefined) {
            delete Memory.creeps[name];
        }
    }
    

  • Dev Team

    Fikal, I've checked your code and found out that the issue is not in this piece of code itself, but it in where it is placed. It is executed right after you create a new creep:

    spawn.createCreep(role.body, creepName, memory);
    ...
    // Your memory cleanup code
    

    So it turns out that you write into memory and immediately delete this piece of memory because the creep scheduled for spawning has not appeared in the Game.creeps object this tick yet.

    In order to fix it, you have to change the order of execution to the opposite:

    // Your memory cleanup code
    ...
    spawn.createCreep(role.body, creepName, memory);
    

    Hope this helps.



  • Artem,

    You are correct! I discovered this an hour or so after I moved some things around. Thanks to everyone for checking and offering suggestions.