admin管理员组文章数量:1332873
I have the following code from the tutorial, except in simulation mode it isn't working..
if(creep.memory.role == 'builder') {
if(creep.energy === 0) {
creep.moveTo(Game.spawns.Spawn1);
Game.spawns.Spawn1.transferEnergy(creep);
}
else {
var targets = creep.room.find(Game.CONSTRUCTION_SITES);
if(targets.length) {
creep.moveTo(targets[0]);
creep.build(targets[0]);
}
}
}
Printing the result of "targets" in the console, responds undefined. Can anyone explain how the "CONSTRUCTION_SITES" constant is working and how to find them inside the room?
I have the following code from the tutorial, except in simulation mode it isn't working..
if(creep.memory.role == 'builder') {
if(creep.energy === 0) {
creep.moveTo(Game.spawns.Spawn1);
Game.spawns.Spawn1.transferEnergy(creep);
}
else {
var targets = creep.room.find(Game.CONSTRUCTION_SITES);
if(targets.length) {
creep.moveTo(targets[0]);
creep.build(targets[0]);
}
}
}
Printing the result of "targets" in the console, responds undefined. Can anyone explain how the "CONSTRUCTION_SITES" constant is working and how to find them inside the room?
Share Improve this question edited Jul 14, 2021 at 14:40 Wenfang Du 11.5k13 gold badges76 silver badges114 bronze badges asked Nov 21, 2014 at 18:56 webecreativewebecreative 1971 gold badge3 silver badges11 bronze badges3 Answers
Reset to default 5The code looks right to me, it seems that you don't actually have any constructions set for the builders to build. Did you use the "Construct" menu on the left to build a road, for example?
I don't know if this has been answered yet, or if it's just that the syntax from the game has changed which is why you initially wrote it this way, but this code works for what you're doing:
var targets = creep.room.find(FIND_CONSTRUCTION_SITES);
In Screeps console.log()
always prints undefined. In line before undefined you can find printed value:
> console.log(Game)
[hh:mm:ss] [object Object]
< undefined
本文标签: javascriptGame Screepscreeproomfind(GameCONSTRUCTIONSITES) not workingStack Overflow
版权声明:本文标题:javascript - Game Screeps - creep.room.find(Game.CONSTRUCTION_SITES); not working - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742315526a2451740.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论