old_contents: var roleHarvester = require('role.harvester');
  var roleUpgrader = require('role.upgrader');
  var roleBuilder = require('role.builder');
  
  module.exports.loop = function () {
  
      var harvesters = _.filter(Game.creeps, (creep) => creep.memory.role == 'harvester');
      var builders = _.filter(Game.creeps, (creep) => creep.memory.role == 'builder');
      var upgraders = _.filter(Game.creeps, (creep) => creep.memory.role == 'upgrader');
      console.log('Harvesters: ' + harvesters.length + ' builders: ' + harvesters.length + ' Upgraders: ' + harvesters.length);
  
      if(harvesters.length < 1) {
          var newName = Game.spawns['Spawn1'].createCreep([WORK,CARRY,MOVE], undefined, {role: 'harvester'});
          console.log('Spawning new harvester: ' + newName);
      }
      
      if(upgraders.length < 1) {
          var newName = Game.spawns['Spawn1'].createCreep([WORK,CARRY,MOVE], undefined, {role: 'upgrader'});
          console.log('Spawning new upgrader: ' + newName);
      }
  
      if(builders.length < 1) {
          var newName = Game.spawns['Spawn1'].createCreep([WORK,CARRY,MOVE], undefined, {role: 'builder'});
          console.log('Spawning new builder: ' + newName);
      }
      
      if(Game.spawns['Spawn1'].spawning) { 
          var spawningCreep = Game.creeps[Game.spawns['Spawn1'].spawning.name];
          Game.spawns['Spawn1'].room.visual.text(
              '🛠️' + spawningCreep.memory.role,
              Game.spawns['Spawn1'].pos.x + 1, 
              Game.spawns['Spawn1'].pos.y, 
              {align: 'left', opacity: 0.8});
      }
  
      for(var name in Game.creeps) {
          var creep = Game.creeps[name];
          if(creep.memory.role == 'harvester') {
              roleHarvester.run(creep);
          }
          if(creep.memory.role == 'upgrader') {
              roleUpgrader.run(creep);
          }
          if(creep.memory.role == 'builder') {
              roleBuilder.run(creep);
          }
      }
  }
new_contents: var roleHarvester = require('role.harvester');
  var roleUpgrader = require('role.upgrader');
  var roleBuilder = require('role.builder');
  
  module.exports.loop = function () {
  
      var harvesters = _.filter(Game.creeps, (creep) => creep.memory.role == 'harvester');
      var builders = _.filter(Game.creeps, (creep) => creep.memory.role == 'builder');
      var upgraders = _.filter(Game.creeps, (creep) => creep.memory.role == 'upgrader');
      console.log('Harvesters: ' + harvesters.length + ' builders: ' + harvesters.length + ' Upgraders: ' + harvesters.length);
  
      if(harvesters.length < 1) {
          var newName = Game.spawns['Spawn1'].createCreep([WORK,CARRY,MOVE], undefined, {role: 'harvester'});
          console.log('Spawning new harvester: ' + newName);
      }
      
      if(upgraders.length < 1) {
          var newName = Game.spawns['Spawn1'].createCreep([WORK,CARRY,MOVE], undefined, {role: 'upgrader'});
          console.log('Spawning new upgrader: ' + newName);
      }
  
      if(builders.length < 1) {
          var newName = Game.spawns['Spawn1'].createCreep([WORK,CARRY,MOVE], undefined, {role: 'builder'});
          console.log('Spawning new builder: ' + newName);
      }
      
      if(Game.spawns['Spawn1'].spawning) { 
          var spawningCreep = Game.creeps[Game.spawns['Spawn1'].spawning.name];
          Game.spawns['Spawn1'].room.visual.text(
              '🛠️' + spawningCreep.memory.role,
              Game.spawns['Spawn1'].pos.x + 1, 
              Game.spawns['Spawn1'].pos.y, 
              {align: 'left', opacity: 0.8});
          for(var i in Memory.creeps) {
              if(!Game.creeps[i]) {
                  delete Memory.creeps[i];
              }
          }
      }
  
      for(var name in Game.creeps) {
          var creep = Game.creeps[name];
          if(creep.memory.role == 'harvester') {
              roleHarvester.run(creep);
          }
          if(creep.memory.role == 'upgrader') {
              roleUpgrader.run(creep);
          }
          if(creep.memory.role == 'builder') {
              roleBuilder.run(creep);
          }
      }
  }
subject: Clean dead creeps from memory on spawn