gpt4 book ai didi

javascript - Screeps 获得所有具有特定内存( Angular 色)的 creeps

转载 作者:数据小太阳 更新时间:2023-10-29 04:36:53 24 4
gpt4 key购买 nike

我正在尝试弄清楚如何让每个 creep 具有特定的内存或 Angular 色,例如变量中的收割机......我似乎无法弄清楚。

我已经试过了:

module.exports = function(){

for(var i in Game.creeps){
if(i.memory == 'Harvester'){
var Harvesters = Game.creeps[i];

if(Harvesters.index < 3){
Game.spawns.Spawn1.createCreep([Game.WORK, Game.CARRY, Game.MOVE],'Harvester'+ Harvesters.length, 'Harvester');
}
}
}
}

但这显然行不通...

最佳答案

您可以使用 harvester Angular 色从 creeps 创建另一个数组:

var harvesters = [];
for(var i in Game.creeps) {
if(Game.creeps[i].memory== 'harvester') {
harvesters.push(Game.creeps[i]);
}

if(harvesters.length < 3){
Game.spawns.Spawn1.createCreep([Game.WORK, Game.CARRY, Game.MOVE], null, 'Harvester');
}

或者使用 lodash:

var harvesters = _.filter(Game.creeps, {memory: 'harvester'});

if(_.size(harvesters) < 3){
Game.spawns.Spawn1.createCreep([Game.WORK, Game.CARRY, Game.MOVE], null, 'Harvester');
}

关于javascript - Screeps 获得所有具有特定内存( Angular 色)的 creeps,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27058687/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com