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?
There are several things to note here:
findNearest()
is not in the room object. Simple fixvar sources = creep.pos.findNearest(Game.SOURCES)
findNearest()
does not return an array of objects, it returns one single object (specifically the closest object) ornull
. The fix here is to change what you have tocreep.moveTo(sources);
(you might want to makesources
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()
, andmakeSnapshot()
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.