-
Notifications
You must be signed in to change notification settings - Fork 66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix RawMemory #7
base: master
Are you sure you want to change the base?
Conversation
Update: with the latest commit adding a setter to the |
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)); } ```
10eddf7
to
dfa538e
Compare
|
@ricochet1k pointed out that my userside fix won't work on the first tick after our runtime resets because the objects are already created before the fix is applied. It would be possible to swap out their prototypes as well, but that adds even more noise to fix something that should already be possible according to documentation. @artch can we expect any progress on this in the near future? If it requires additional changes on my side let me know. |
This solution is perfect. Adding the setter to the global Right now if you try and set it up using Another way I could fix it in the current API is by overwriting the @artch, or any other Screeps devs, seeing as how this solution is so simple and effective, is there any reason this hasn't been merged and deployed yet? Is there anything we can do as a community to move this forward? |
I was hoping I could avoid double parsing the memory (once on my own using |
My old PR #4 is also needed to really use RawMemory (currently there is no way to spawn creeps without using Memory) |
@googol, I do like your handling of create creep memory better, don't try and set anything if nothing is passed. However, if they adopted @PostCrafter's method of allowing you to set the global memory object, then as long as you set up your custom memory object before hand using RawMemory, it would use your implementation instead of the built in memory. |
For anyone interested in using RawMemory already, I finally have a solution. In a discussion on the slack chat, about reusing Memory in subsequent contexts, @ags131 brought up that calling This will allow us to use a slight variation of the example in the serialization paragraph of Memory. delete global.Memory
global.Memory = JSON.parse(RawMemory.get()); //on the first access to Memory object
// ...your script
RawMemory.set(JSON.stringify(Memory)); |
@PostCrafter. Exciting! I'll have to try that! |
I wanted to report back. I have tried @PostCrafter's technique and it worked for me. If I delete Well done @PostCrafter! I still think that this PR is a good one to merge because It makes using RawMemory more straight forward. However, I'm not longer desperate for it because we have a work around. |
@artch With the recent activity regarding PRs, what is the status on this one? |
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
andSpawn#Memory
alwaysaccess
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 differentobjects.
The solution to this would be tracking down why setting
Memory
(orglobal.Memory
) in code doesn't changeglobals.Memory
, but I don'thave enough experience with the screeps server and the vm module.
For now this just makes the
memory
property configurable, so we canchange it to actually access our version of the parsed Memory.
Test case: