adding then accessing memory on controller

172 Views Asked by At
if (this.controller && !this.controller.memory) this.controller.memory = { containerid: null, linkid: null };

later I have this:

if (creep.room.controller.memory) {//do code}

for some reason when I try to access it from the creep it fails (I hit the else condition) What am I missing?

1

There are 1 best solutions below

0
KBill On BEST ANSWER

Controller have NO Memory shorthand in properties like Creeps.

Like most of things in Screeps, StructureController have no Memory. See Screeps Docs

You must record Creeps, Rooms, Spawns into Memory, and all other stuff! The Screeps Objects like Creeps, Spawns, etc... doesn't stock memory in their own properties but into the Memory Object.

Don't add memory to objects like you are trying to do! It's a trap! I suggest you to write the Controller Memory in his Room Memory.

Memory.rooms[controller.room.name]

I don't know how you access your controller. If you accessing Controller with the name of the Room:

// Your Room. Random example: "E12N36" 
let room = Game.rooms[room_name]
let controller = room.controller

// Add into the Room Memory your information about/for/with controller 
room.memory.controllerOfRilcon = {
   name: "Not",
   sure_name: "Sure",
   NumberOfPokeballs: "FullOfBits",
   Nanani: "Done",
   Nanana: "TryToThink"
}

You can see in the documentation the VERY IMPORTANT POINT how Memory works Documentation-CreepMemory

Game.creeps[name].memory is just a shorthand for accessing the Object Memory.creeps[name]. It's the Object Memory who contains the real datas of the memories.

NO MEMORY in OBJECTS !