我的内存有问题。它应该存储我的所有数据(而不是对象),但它会不时重置。 这是示例:
Memory.creeps_idx = 0;
module.exports.loop = function () {
console.log("c_idx:", Memory.creeps_idx, Game.time);
if(Memory.creeps_idx==0)
{
Memory.creeps_idx+=1;
}
}
这是控制台的输出。
[13:41:01]c_idx: 0 1115
[13:41:03]c_idx: 1 1116
[13:41:05]c_idx: 0 1117
[13:41:07]c_idx: 1 1118
[13:41:09]c_idx: 1 1119
[13:41:11]c_idx: 1 1120
[13:41:13]c_idx: 1 1121
[13:41:15]c_idx: 1 1122
[13:41:17]c_idx: 0 1123
[13:41:19]c_idx: 1 1124
[13:41:21]c_idx: 1 1125
[13:41:23]c_idx: 1 1126
[13:41:25]c_idx: 1 1127
你能告诉我为什么 creeps_idx 将值更改为 0 吗? (这是在模拟器中测试的)
最佳答案
基本上,module.exports.loop 之外的任何内容都会每隔几个周期运行一次。这就是为什么 cree_idx 在原始示例中被重置,以及您的解决方案有效的原因。
What is new here is the way you main module is executed. In the old-style architecture, it is executed every tick, and every module required from it is also executed every tick. In the new architecture, your main module should contain the module.exports.loop function which is executed in a game loop, while the rest of the main module contents are executed only after a new global is instantiated.
http://support.screeps.com/hc/en-us/articles/204825672-New-main-loop-architecture
关于javascript - Screeps - 内存中的属性重置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43963772/