Defining Individual sources



  • So I currently have code that defines the amount of sources in a room by using the creep's memory...

    var source = creep.room.find(FIND_SOURCES).;
    var NumberOfSources = source.length;
    

    I'm trying to assign a group/team of creeps to certain sources

    For example: miningTeam1 would go to the closest source, miningTeam2 would go to the second closest source, miningTeam3 would go to the third closest source, etc...

    I'm having trouble finding a way to separate each individual source, any help would be appreciated thanks!



  • You can try tracking each source by its ID.

    var allSources = room.find(FIND_SOURCES);
    for (var source of allSources) {
        var id = source.id;
        // save the ID somewhere
    }
    

    Then, on another tick, you can get the source back from its ID:

    var source = Game.getObjectById(id);
    


  • store the sources in room memory/global (the id's in an array) and then pull from that and use Game.getObjectById

    room.find's are cpu intensive and something you want to avoid doing every tick



  • @jbyoshi

    So I'm having trouble saving the id.

    pretend that this is a source id: a15a83d0649349cfc8394ee1

    var source1 = Game.getObjectById('a15a83d0649349cfc8394ee1');

    if(source1 > 0)
    {
        Game.spawns.Spawn1.createCreep([WORK,WORK,MOVE], undefined, {role: 'Driller1'});
    }
    

    I am still trying to figure out how to define a source by its id, any help would be appreciated.



  • @lucio

    I figured out that you can't grab the ID straight from the game, i'm trying to push the id's into an array instead. However, it says that room is undefined.

    Note that I am using the training mode in order to play Screeps; I do not have a subscription yet.



  • @Lucio

    I am struggling with this exact same problem. Currently, my creeps only harvest from one resource using creep.room.find(FIND_SOURCES). I want to create a team that harvests the other source in my room but can't find any instruction on how to order the creeps to go to a particular source ID. Did you get any further in sorting this out?



  • @shibdib room.finds are cheap as chips if you're not filtering them