0

I am attempting to save the source ID and the ID of which spawn is currently mining the source to memory under the current spawn in the room. Once I have that saved I can easily assign miners to each source without having to do FIND_SOURCES. Doing it this way will lower my CPU usage.

My current issue is that it only saves the source ID and not the custom object I am attempting to create. Any help with correcting this issue would be greatly appreciated.

Here is the current code I am using:

    if(!spawn.memory.sources){
        //spawn.memory.sources = {}; //Add it
        var roomSources = spawn.room.find(FIND_SOURCES);
        console.log("loading memory");
        for(var i in roomSources){
            var source = {id:roomSources[i].id, currentMinerId: null};
           spawn.memory.sources[i] = source; 
        }
    }
JoBaxter
  • 710
  • 2
  • 12
  • 23

1 Answers1

0

I was able to correct this issue with the following code. Hope it is helpful for someone else.

    if(!spawns.memory.roomSources){
        spawns.memory.roomSources=[];
        var energySources = spawns.room.find(FIND_SOURCES);
        for(var i in energySources){
            spawns.memory.roomSources[i] = {sourceId: energySources[i].id, currentMinerId: null};

        }
    }
JoBaxter
  • 710
  • 2
  • 12
  • 23