gpt4 book ai didi

screeps - 无法生成有内存的 creep

转载 作者:行者123 更新时间:2023-12-02 02:57:45 26 4
gpt4 key购买 nike

首先,我是这个游戏的新手,但我以前就知道 js。我遇到的问题是我在模拟器中玩耍的结果。

我试图生成一个 creep,我首先修改了 example in the tutorial :

Game.spawns['HQ'].spawnCreep(
[WORK,CARRY,MOVE],
name,
{memory: {role: r}});

但这只会产生一个 creep,它的内存是 undefined

enter image description here

我也试过在调用 spawnCreep 后设置内存:

Game.creeps[name].memory = {
role: r
};

但它会导致相同的“错误”。

我错过了什么?

更新1:

情况变得更糟...我决定扔掉我的整个代码库,并用教程中的确切代码替换它。内存仍然是 undefined...

var roleHarvester = require('role.harvester');
var roleUpgrader = require('role.upgrader');

module.exports.loop = function () {

for(var name in Memory.creeps) {
if(!Game.creeps[name]) {
delete Memory.creeps[name];
console.log('Clearing non-existing creep memory:', name);
}
}

var harvesters = _.filter(Game.creeps, (creep) => creep.memory.role == 'harvester');
console.log('Harvesters: ' + harvesters.length);

if(harvesters.length < 2) {
var newName = 'Harvester' + Game.time;
if(Game.spawns['HQ'].spawnCreep([WORK,CARRY,MOVE], newName,
{memory: {role: 'harvester'}}) === OK) {
console.log('Spawning new harvester: ' + newName);
};
}

if(Game.spawns['HQ'].spawning) {
var spawningCreep = Game.creeps[Game.spawns['HQ'].spawning.name];
Game.spawns['HQ'].room.visual.text(
'🛠️' + spawningCreep.memory.role,
Game.spawns['HQ'].pos.x + 1,
Game.spawns['HQ'].pos.y,
{align: 'left', opacity: 0.8});
}

for(var name in Game.creeps) {
var creep = Game.creeps[name];
if(creep.memory.role == 'harvester') {
roleHarvester.run(creep);
}
if(creep.memory.role == 'upgrader') {
roleUpgrader.run(creep);
}
}
}

更新2:
我决定在私有(private)服务器上尝试相同的代码(也就是,不是像以前那样在模拟中),现在代码可以正常工作了。这只留下一个结论,模拟有问题。

最佳答案

尝试在 r 周围放置一个“'”以将其定义为字符串。据我所知,r 是 undefined

Game.spawns['HQ'].spawnCreep([WORK,CARRY,MOVE], 
name,
{memory: {role: 'r'}});

关于screeps - 无法生成有内存的 creep,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48268177/

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