Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This allows actually using the custom serialization explained at http://support.screeps.com/hc/en-us/articles/203016642-Working-with-memory Right now `Creep#memory`, `Flag#memory`, `Room#memory` and `Spawn#Memory` always access `globals.Memory` which is not changeable from inside users code. Therefor Memory parsing will happen twice, once by the users code and once by the first access to `globals.Memory`, resulting in two different objects. The solution to this would be tracking down why setting `Memory` (or `global.Memory`) in code doesn't change `globals.Memory`, but I don't have enough experience with the screeps server and the vm module. For now this just makes the `memory` property configurable, so we can change it to actually access our version of the parsed Memory. Test case: ``` module.exports.loop = function loop() { Memory = JSON.parse(RawMemory.get()); const creepName = "test"; const creep = Game.creeps[creepName]; if (!creep) { _.first(_.values(Game.spawns)).createCreep([MOVE], creepName); } else { console.log(`--- Test case (tick: ${Game.time}) ---`); Memory.creeps[creepName].tick = Game.time; const gMemory = Memory.creeps[creepName].tick; const cMemory = creep.memory.tick; if (globalMemoryTick === creepMemoryTick) { console.log(`success: ${gMemory} === ${cMemory}`); } else { console.log(`failed: ${gMemory} !== ${cMemory}`); } } RawMemory.set(JSON.stringify(Memory)); } ```
- Loading branch information