Javascript findNearest,FindRange-如何在尖叫中使用?

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

我尝试使用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
时间:11:6

如何使用此方法和FindRange,以便它们不会导致此错误?

正如我所看到的,文档已经更新,现在有一些示例代码


这里有几件事需要注意:

  • findNearest()
    不在房间对象中。简单修复
    var sources=screw.pos.findNearest(Game.sources)
  • findNearest()
    不返回对象数组,它返回单个对象(特别是最近的对象)或
    null
    。这里的修复方法是改变你必须的
    screw.moveTo(sources)(您可能希望将
    源代码设置为单数,以避免混淆)
  • 您没有提供代码,但我猜您正在执行类似于
    screw.room.findInRange()
    的操作,而且它不在房间对象中,而是在pos中,因此它看起来像这样,
    screw.pos.findInRange()
  • 令人困惑的是,room中仅有的功能是
    find()
    lookAt()
    findPath()
    、和
    makeSnapshot()
    ,而pos还有很多功能(在文档的roomposition中列出)

  • 如果您在文档中查找room和roomposition并滚动到底部,您可以看到哪些功能位于哪个对象中。

    请在回答中包含您直接链接的内容;链接腐烂。