Setting creep role in Memory not working



  • Hello,

     

    I tried automating the creation of creeps but I still fail to set the role of a creep correctly.

    I use different approaches from the forum and tutorials and the still do not work:

     memory = {};
    memory['role'] = "harvester";
    var creep = Game.spawns.Spawn1.createCreep([WORK, WORK, WORK, CARRY, MOVE], null, memory);
    if (_.isString(creep) && Memory.creeps[creep]){
    Memory.creeps[creep].role = 'harvester';
    }

  • SUN

    There is a tutorial in a simulation mode, 
    you can see the creep creation process (including role setting) there.



  • I already tried the exact code from the documentation:

    Game.spawns.Spawn1.createCreep([WORK, WORK, WORK, CARRY, MOVE], null, {role: 'harvester'});

    This still does not work...



  • Define "does not work" - the code you show is definitely correct. I'm guessing your actual problem is somewhere else.



  • Well after executing the code and inspecting the memory of a newly spawned creep the creep does not have a role set...



  • I'm creating creeps the exact same way, except that I give them names myself: 

    Game.spawns.Spawn1.createCreep([WORK, WORK, WORK, CARRY, MOVE], "UniqueName", {role: 'harvester'});

    and it works perfectly for me. Try if you have the same issue if you give them a name yourself - if that works, this might be a bug. 

     

    If that doesn't work either: Do you have any other code that messes with Memory? 

    The way creep memory works is that the spawn instantly creates the memory entry in Memory.creeps, but the creep itself is only created / starts spawning on the next tick - so if you for example have a script that cleans up memory of non-existing creeps, that would have to be run before the code that spawns new creeps, not after, or exactly what you are describing happens.