I try to use findNearest like that:
var sources = creep.room.findNearest(Game.SOURCES)
creep.moveTo(sources[0]);
creep.harvest(sources[0]);
and this is what i get:
TypeError: undefined is not a function
at module.exports:5:28
at <main>:11:6
How to use this method and findInRange so that they don't cause this error?
An AI can request the spawn to spawn new creeps. When enough energy is available in its storage device, the required energy will be subtracted from it and use it to spawn new creeps. The spawn is important because it's one of the first elements available in the game that can be used.
There are several things to note here:
findNearest()
is not in the room object. Simple fix var sources = creep.pos.findNearest(Game.SOURCES)
findNearest()
does not return an array of objects, it returns one single object (specifically the closest object) or null
. The fix here is to change what you have to creep.moveTo(sources);
(you might want to make sources
singular to avoid confusion)creep.room.findInRange()
and again it's not in the room object it's in pos so it would look like this instead, creep.pos.findInRange()
.find()
, lookAt()
, findPath()
, and makeSnapshot()
whereas pos has quite a few more (listed in roomposition in the docs)If you look in the documentation here for room and here for roomposition and scroll to the bottom you can see which functions are in which object.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With