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
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742315526a4420762.html
评论列表(0条)