Defining the Amount of Sources in a Room
-
Is there a way to define the amount of sources in a room? If I can then I can spawn an appropriate number of creeps for each source.
-
Can't you just call something like
.find(FIND_SOURCES).length
to determine the number of sources in a room?
-
Maybe you could try
let source = creep.room.find(FIND_SOURCES) let NumberOfSources = source.length
-
That works!
if (numberOfDrills < source.length) { name = Game.spawns.Spawn1.createCreep([WORK,WORK,MOVE], undefined, {role: 'Driller'}); }
-
@gankdalf Ill see what I can do about your code but I'm going for a way to define the amount of sources and use it anywhere in my code.
-
Define 'sources' as a proporty/function on the Room object by extending it. Up to you if you want to return the actual sources, or the length of the array...
-
So the code only seemed to work for a little bit and when I came back it didn't work. I assume its because I didn't spawn any creeps and the creep.room.find(FIND_SOURCES) couldn't be defined without any creeps spawned.
-
Just keep that in mind
-
Yes, you would need to get the room some other way, since no creeps exist you obviously can't use
creep.
...whatever
.You can get it with
Game.rooms[roomName]
or any other method for getting the room. The only requirement is that you have vision of the room, which doesn't require creeps.