在Screep中,我这段代码不能工作:
var sources = creep.room.find(Game.FIND_SOURCES_ACTIVE);它是这样写的:
Cannot read property 'find' of undefined我一直在四处寻找,但找不到任何其他的方法来寻找来源。
此外,我注意到大多数人的代码都不能工作,甚至教程的代码在放入真正的游戏中时也不再工作。
发布于 2017-02-28 17:26:32
我不能完全确定你的问题,因为我没有你的完整代码,但一个问题可能是creep没有定义。
您需要在代码中的某处定义creep,例如循环遍历游戏或房间中的每个爬虫。
var roleMiner = require('role.miner') // role.miner being the module name for miner actions
for(var name in Game.creeps) {
var creep = Game.creeps[name];
//
// do whatever you wish with the current selected creep.
//
// most of the time you will call a module similar to what the tutorials suggest and put your actions for it in there
//
if(creep.memory.role == 'miner'){
roleMiner.run(creep); // passes the current selected creep to the run function in the module
}
}因此,在你的roleMiner模块中,你应该有一些东西来定义你的挖掘器操作。
var roleMiner = {
run: function(creep) {
// this one returns an array of the sources that are in the room with the creep
var sourcesRoom = creep.room.find(FIND_SOURCES);
// this one returns the source object which is closest to the creeps positon
var sourcesClose = creep.pos.findClosestByRange(FIND_SOURCES);
}
}
module.exports = roleMiner;希望这能有所帮助。
发布于 2020-01-29 15:33:49
爬虫有一些..。机制,当你在每个游戏节拍之间共享你的数据。如果您在全局内存对象中存储任何内容,您的数据将丢失其所有原型。若要恢复原型,请使用Object.setPrototypeOf(爬行,Creep.prototype)或根据爬行id创建新的爬行对象。
发布于 2017-01-18 05:20:51
我想你要找的是:
var sources = creep.pos.findClosestByRange(Game.SOURCES);或
var sources = creep.pos.findClosestByPath(Game.SOURCES);https://stackoverflow.com/questions/41707132
复制相似问题