Kind of old but I use Spawn.prototype.getCreepName = function(role){ var creepName = role + '_0'; for(i = 0; i < 9999 ; i++) { creepName = role + '_' + i; if(Game.creeps[creepName] === undefined || Game.creeps[creepName] === null) break; } return creepName; }