First attempt at logic to automate creep creation
-
Hey Guys -
I have been making alot of progress with my game, I now have functions that do all the roles I currently need. But now im trying to automate creep creation and im struggling.Heres the code im using:
var hc = 0; var uc = 0; var bc = 0; while ( Games.creeps < 10 ){ if (Memory.role.'harvester' < 3) Game.spawns.Spawn1.createCreep( [WORK, CARRY, MOVE], 'Harvester[hc++]', { role: 'harvester' } ); else if (Memory.role.'upgrade' < 3) Game.spawns.Spawn1.createCreep( [WORK, CARRY, MOVE], 'Upgrade[uc++]', { role: 'upgrade' } ); else if (Memory.role.'builder' < 1) Game.spawns.Spawn1.createCreep( [WORK, WORK, CARRY, MOVE], 'Builder[bc++]', {role: 'builder'} ); else if (Memory.role.'harvester' < 5 && Memory.role.'upgrade' == 2 && Memory.role.'builder' == 1) Game.spawns.Spawn1.createCreep( [WORK, CARRY, MOVE], 'Harvester[hc++]', { role: 'harvester' } ); }
Not looking for a hand out but if someone could point me in the right direction, it would be greatly appreciated!
Sorry for all the nooby questions as i struggle through it...
-
as an FYI - i kinda got this to work... the script runs but now its just not working... i dont think my increment is appending correctly and im having duplicate creeps.
var hc = 0; var uc = 0; var bc = 0; if(!Game.spawns.Spawn1.spawning) { if (Game.spawns.Spawn1.room.find(FIND_MY_CREEPS, { filter: function(creep){ return creep.memory.role == 'harvester'; }}).length < 3) Game.spawns.Spawn1.createCreep( [WORK, CARRY, MOVE], 'Harvester' + ++hc, { role: 'harvester' } ); else if (Game.spawns.Spawn1.room.find(FIND_MY_CREEPS, { filter: function(creep){ return creep.memory.role == 'upgrade'; }}).length < 3) Game.spawns.Spawn1.createCreep( [WORK, CARRY, MOVE], 'Upgrade' + ++uc, { role: 'upgrade' } ); else if (Game.spawns.Spawn1.room.find(FIND_MY_CREEPS, { filter: function(creep){ return creep.memory.role == 'harvester'; }}).length < 6 && Game.spawns.Spawn1.room.find(FIND_MY_CREEPS, { filter: function(creep){ return creep.memory.role == 'upgrade'; }}).length >= 3) Game.spawns.Spawn1.createCreep( [WORK, CARRY, MOVE], 'Harvester' + ++hc, { role: 'harvester' } ); else if (Game.spawns.Spawn1.room.find(FIND_MY_CREEPS, { filter: function(creep){ return creep.memory.role == 'builder'; }}).length > 1) Game.spawns.Spawn1.createCreep( [WORK, WORK, CARRY, MOVE], 'Builder' + ++bc, {role: 'builder'} ); }
Still trudging through - i have to admit im really enjoying this process....
-
Hi,
get to your solution step by step.
I would recommend:- Put the "find" routine in a variable.
- For debug reasons, do a "console.log(varFindHarvester);" and so on.
- Then do the if part
- Maybe remove the name generation for debugging purposes
Should lead you to the solution.
-
And don't forget. This script is running EVERY Game Tick. So you have to store your vars "hc" "uc" "bc" somewhere else. Maybe in the memory Object of the room
Alternatively don't give names or use a random number.