我在玩爬虫游戏(http://screeps.com),我试着用房车模块来过滤我的收割机,让它从其余的爬虫中过滤出来。下面的代码应该可以工作,但是当我运行它时,我会得到一个ReferenceError: _ is not defined at <main>:6:18。知道怎么回事吗?
var harvesters = _.filter(Game.creeps, {memory: 'harvester'});
if(_.size(harvesters) < 3 && Memory.creep_queue.length===0) {
Memory.creep_queue.push('harvester')
}发布于 2014-11-21 17:44:05
在使用送交模块时,有必要要求它像下面所示的变量那样在模块的请求中使用,然后它应该可以工作:
var _ = require('lodash');发布于 2014-11-22 00:12:25
更新
您还可以这样编写代码:
var harvesters = room.find(Game.creeps, {
filter: {memory: 'harvester'}
});
if(harvesters.length < 3 && Memory.creep_queue.length === 0) {
Memory.creep_queue.push('harvester');
}从2014-12-01年开始,就没有必要以一种无趣的方式找到room了。现在有一个全局函数Game.getRoom()。
旧片段:唯一的问题是有
room值,但是您可以从eg获得它。Game.spawns.Spawn1.room。
https://stackoverflow.com/questions/27067243
复制相似问题