gpt4 book ai didi

javascript - Screeps:在 creeps 内存中存储对源的引用?

转载 作者:数据小太阳 更新时间:2023-10-29 03:47:57 25 4
gpt4 key购买 nike

引人入胜的游戏!

寻找一个示例,说明如何在 creep 的内存中保留对特定能源的引用。似乎存储实际的源对象不起作用(?)。

最佳答案

您不能存储对象实例,但可以存储它们的 ID。

if(!creep.memory.targetSourceId) {
var source = creep.pos.findNearest(Game.SOURCES_ACTIVE);
creep.memory.targetSourceId = source.id;
}

然后你可以使用Game.getObjectById()找到这个特定的来源。

var source = Game.getObjectById(creep.memory.targetSourceId);
creep.moveTo(source);

关于javascript - Screeps:在 creeps 内存中存储对源的引用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27061998/

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