Skip to content
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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Commits on Feb 3, 2017

  1. Make memory property configurable

    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));
    }
    ```
    RiftLurker authored and Leo Friedrichs committed Feb 3, 2017
    Configuration menu
    Copy the full SHA
    e8c9365 View commit details
    Browse the repository at this point in the history
  2. Add setter to global.Memory

    RiftLurker authored and Leo Friedrichs committed Feb 3, 2017
    Configuration menu
    Copy the full SHA
    dfa538e View commit details
    Browse the repository at this point in the history