Only pick up energy?



  • Hey guys!

     

    So, I have my creeps pick up droppen energy, so it's not lost when a creep dies or when invaders drop energy. now. sometime the invaders are boosted and have these combined minerals on them, which I had one time picked up by a creep, which then went on and mined forever, beavause it couldn't fill the whole capacity with energy, as there was already some minerals there that took up space. This is my code for the pickup:

    var dropenergy = creep.pos.findClosestByPath(FIND_DROPPED_ENERGY, {
    filter: (d) => {return (d.mineralType == RESOURCE_ENERGY)}});
    if (dropenergy) {
    if (creep.pickup(dropenergy) == ERR_NOT_IN_RANGE) {
    creep.moveTo(dropenergy)
    }
    }

    else {
    //harvest if no dropped energy
    var sources = creep.room.find(FIND_SOURCES);
    if(creep.harvest(sources[0]) == ERR_NOT_IN_RANGE) {
    creep.moveTo(sources[0]);
    }
    }

    I added the filter to try and do it, but now it doesn't pick up anything. without the filter, it picked up everything. I also included the code for harvesting afterwards.

     

    #

    edit: also, how do I post code here with markup and stuff?

     



  • In your filter you should use 

    filter: (d) => {return (d.resourceType == RESOURCE_ENERGY)}

     

    Dropped resource is not Mineral, http://support.screeps.com/hc/en-us/articles/203016362-Resource



  • Thank you for the quick answer, I will try that now. It's weird though, it doesn't show up in yellow in my markup.