Javascript findNearest,FindRange-如何在尖叫中使用?
我尝试使用findNearest,如下所示:Javascript findNearest,FindRange-如何在尖叫中使用?,javascript,screeps,Javascript,Screeps,我尝试使用findNearest,如下所示: var sources = creep.room.findNearest(Game.SOURCES) creep.moveTo(sources[0]); creep.harvest(sources[0]); 这就是我得到的: TypeError: undefined is not a function at module.exports:5:28 at <main>:11:6 TypeError:未定义不是函数 出口时间:5:28
var sources = creep.room.findNearest(Game.SOURCES)
creep.moveTo(sources[0]);
creep.harvest(sources[0]);
这就是我得到的:
TypeError: undefined is not a function
at module.exports:5:28
at <main>:11:6
TypeError:未定义不是函数
出口时间:5:28
时间:11:6
如何使用此方法和FindRange,以便它们不会导致此错误?正如我所看到的,文档已经更新,现在有一些示例代码
这里有几件事需要注意:
findNearest()
不在房间对象中。简单修复var sources=screw.pos.findNearest(Game.sources)
findNearest()
不返回对象数组,它返回单个对象(特别是最近的对象)或null
。这里的修复方法是改变你必须的screw.moveTo(sources)代码>(您可能希望将源代码设置为单数,以避免混淆)
screw.room.findInRange()
的操作,而且它不在房间对象中,而是在pos中,因此它看起来像这样,screw.pos.findInRange()
find()
、lookAt()
、findPath()
、和makeSnapshot()
,而pos还有很多功能(在文档的roomposition中列出)如果您在文档中查找room和roomposition并滚动到底部,您可以看到哪些功能位于哪个对象中。请在回答中包含您直接链接的内容;链接腐烂。