gpt4 book ai didi

javascript - 产卵者不会停止产卵收割机

转载 作者:行者123 更新时间:2023-12-02 13:48:09 25 4
gpt4 key购买 nike

我正在尝试根据我之前在 main 中的变量中设置的设定数量限制在 main 中设置自动生成脚本。但是,由于某种原因,脚本执行执行异常。

脚本:

var roleHarvester = require('role.harvester');
var roleUpgrader = require('role.upgrader');
var roleSpawner = require('role.spawner');
var trashHandler = require('helper.trashHandler');

module.exports.loop = function () {
//Start by cleaning memory
trashHandler.run(Memory);

//Default Number of Creeps
var max_harvesters = 2;
var max_upgraders = 3;

for(var name in Game.creeps) {
var creep = Game.creeps[name];

if (creep.memory.role == 'harvester'){
roleHarvester.run(creep);
} else if (creep.memory.role == 'upgrader'){
roleUpgrader.run(creep);
}
}

var harvesters = _.filter(Game.creeps,(creep)=>creep.memory.role == 'harvester');
var upgraders = _.filter(Game.creeps,(creep)=>creep.memory.role == 'upgrader');

for (var name in Game.spawns){
var spawner = Game.spawns[name];

console.log(harvesters.length < max_harvesters);
console.log(max_harvesters);
console.log(harvesters.length);


if (harvesters.length < max_harvesters){
roleSpawner.spawnHarvester(spawner);
} else if (upgraders.length < max_upgraders){
roleSpawner.spawnHarvester(spawner);
}
}
}

最后的控制台输出显示它按照预期工作,但脚本执行忽略了 if 语句执行为 false 的事实。

[8:17:20 PM]false

[8:17:20 PM]2

[8:17:20 PM]9

[8:17:20 PM]harvester spawn falied: -6

[8:17:23 PM]false

[8:17:23 PM]2

[8:17:23 PM]10

最佳答案

天哪......刚刚注意到我正在为两者调用spawnHarvester函数。哈哈。

关于javascript - 产卵者不会停止产卵收割机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41195059/

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