<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Harvesting from multiple sources within a room]]></title><description><![CDATA[<p>I cannot understand how to use a source's Id to create a designated team of harvesters to go to that resource instead of the one closest to my spawn. Currently, all my harvesters only go to the primary source using this code:</p>
<pre><code>run: function(creep) {
    if(creep.carry.energy &lt; creep.carryCapacity) {
        var sources = creep.room.find(FIND_SOURCES);
        if(creep.harvest(sources[0]) == ERR_NOT_IN_RANGE) {
            creep.moveTo(sources[0], {visualizePathStyle: {stroke: '#ffaa00'}});
        }
    }
</code></pre>
<p>Please, could someone help me understand how I can store a particular source's Id into memory and then instruct a separate team of harvesters to go to that source? I have created a new role - role.southharvester - but cannot formulate the code to get it to harvest the other source.</p>
]]></description><link>http://screeps.com/forum/topic/2364/harvesting-from-multiple-sources-within-a-room</link><generator>RSS for Node</generator><lastBuildDate>Wed, 18 Nov 2026 08:12:32 GMT</lastBuildDate><atom:link href="http://screeps.com/forum/topic/2364.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 28 Sep 2018 14:17:57 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Harvesting from multiple sources within a room on Fri, 28 Sep 2018 14:20:58 GMT]]></title><description><![CDATA[<p>I cannot understand how to use a source's Id to create a designated team of harvesters to go to that resource instead of the one closest to my spawn. Currently, all my harvesters only go to the primary source using this code:</p>
<pre><code>run: function(creep) {
    if(creep.carry.energy &lt; creep.carryCapacity) {
        var sources = creep.room.find(FIND_SOURCES);
        if(creep.harvest(sources[0]) == ERR_NOT_IN_RANGE) {
            creep.moveTo(sources[0], {visualizePathStyle: {stroke: '#ffaa00'}});
        }
    }
</code></pre>
<p>Please, could someone help me understand how I can store a particular source's Id into memory and then instruct a separate team of harvesters to go to that source? I have created a new role - role.southharvester - but cannot formulate the code to get it to harvest the other source.</p>
]]></description><link>http://screeps.com/forum/post/11420</link><guid isPermaLink="true">http://screeps.com/forum/post/11420</guid><dc:creator><![CDATA[NanoCraft]]></dc:creator><pubDate>Fri, 28 Sep 2018 14:20:58 GMT</pubDate></item><item><title><![CDATA[Reply to Harvesting from multiple sources within a room on Invalid Date]]></title><description><![CDATA[<p>sources is a list. Your looking at the first item in the list. Try looking at the second one.</p>
<p>sources[0] is the source you are minding from</p>
<p>sources[1] is a diffrant source.</p>
<p>sources[2] is yet a diffrant source (provided there is 3 sources in the room)</p>
]]></description><link>http://screeps.com/forum/post/11422</link><guid isPermaLink="true">http://screeps.com/forum/post/11422</guid><dc:creator><![CDATA[alaricdragon]]></dc:creator><pubDate>Invalid Date</pubDate></item><item><title><![CDATA[Reply to Harvesting from multiple sources within a room on Fri, 28 Sep 2018 18:20:25 GMT]]></title><description><![CDATA[<p><code>Source</code> is the game object, each game object are contained <code>id</code> property. The <code>room.find</code> is returned list of <code>Source</code> objects. So you can get list of sources by code:</p>
<pre><code>var listSources = creep.room.find(FIND_SOURCES)
</code></pre>
<p>Than you can save this id on the creep memory:</p>
<pre><code>creep1.memory.sourceID = listSources[0].id;
creep2.memory.sourceID = listSources[1].id;
</code></pre>
<p>After it your harvester function can look like this:</p>
<pre><code>run: function(creep) {
    if(creep.carry.energy &lt; creep.carryCapacity) {
        var source = Game.getObjetcByID(creep.memory.sourceID)
        if(creep.harvest(source) == ERR_NOT_IN_RANGE) {
            creep.moveTo(source, {visualizePathStyle: {stroke: '#ffaa00'}});
        }
    }
</code></pre>
<p>This is only sketch how it's can be look.</p>
]]></description><link>http://screeps.com/forum/post/11423</link><guid isPermaLink="true">http://screeps.com/forum/post/11423</guid><dc:creator><![CDATA[Flyasd1]]></dc:creator><pubDate>Fri, 28 Sep 2018 18:20:25 GMT</pubDate></item><item><title><![CDATA[Reply to Harvesting from multiple sources within a room on Tue, 02 Oct 2018 17:27:07 GMT]]></title><description><![CDATA[<p>It's better not to worry about assigning sources directly with your code.</p>
<p>My code will filter an array based on the source id. The miners will have the source id in their memory.</p>
<p>so you have an array of miners myMiners = []; You place your miner creeps in them, filtering Game.creeps for the source id.</p>
<p>For my code, I just have one miner per source...so if there isn't a miner, it'll spawn one.</p>
<pre><code>    for(let sourceIndex in Game.rooms[homebase].memory.sources){
        myMiners = _.filter(Game.creeps, i =&gt; i.memory.sourceId === sourceIndex);
        if(myMiners.length &lt; 1){
            Game.spawns[0].spawnCreep(minerBody, randomName, memory: {sourceId: 
                     sourceIndex})
        }
    }
</code></pre>
]]></description><link>http://screeps.com/forum/post/11475</link><guid isPermaLink="true">http://screeps.com/forum/post/11475</guid><dc:creator><![CDATA[Famine]]></dc:creator><pubDate>Tue, 02 Oct 2018 17:27:07 GMT</pubDate></item><item><title><![CDATA[Reply to Harvesting from multiple sources within a room on Wed, 03 Oct 2018 19:36:59 GMT]]></title><description><![CDATA[<p>Thanks a great deal for your help guys, I managed to use your advice to get the harvesters to use both sources in my room currently just be writing sources[1] but I will work on upgrading to a dedicated stationary miner soon. Currently, I am having trouble getting my distance harvester to reliably go to a neighbouring room and harvest a source there. It goes there sometimes (with some variations of the code below but not consistently). If anyone could give me any advice on how to tweak it I would be very grateful:</p>
<p>var roleDistanceharvester = {</p>
<pre><code>/** @param {Creep} creep **/
run: function(creep) {
    if(creep.carry.energy &lt; creep.carryCapacity) {
        var prospect = creep.moveTo(new RoomPosition(20,1, 'W57S45'))};
        
        
        if((creep.pos.isEqualTo(20,1, 'W57S45') || creep.pos.isNearTo(20,1, 'W57S45')) &amp;&amp; creep.carry.energy &lt; creep.carryCapacity) {
            var sources = creep.room.find(FIND_SOURCES);
        if(creep.harvest(sources[0]) == ERR_NOT_IN_RANGE) {
            creep.moveTo(sources[0], {visualizePathStyle: {stroke: '#ffaa00'}});
        }
    }

    else {
        if(creep.carry.energy = creep.carryCapacity) {
        const stores = creep.pos.findClosestByPath(FIND_STRUCTURES, {
                filter: (s) =&gt; (s.structureType == STRUCTURE_EXTENSION || s.structureType == STRUCTURE_SPAWN || s.structureType == STRUCTURE_CONTAINER || s.structureType == STRUCTURE_STORAGE) &amp;&amp;
                        s.energy &lt; s.energyCapacity});
                        
        var targets = creep.moveTo(new RoomPosition(12,16, 'W57S44'));
        if(stores) {
            if(creep.transfer(stores, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
                creep.moveTo(stores, {visualizePathStyle: {stroke: '#ffffff'}});
            }
        }
    }
 }
</code></pre>
<p>}
};
module.exports = roleDistanceharvester;</p>
]]></description><link>http://screeps.com/forum/post/11496</link><guid isPermaLink="true">http://screeps.com/forum/post/11496</guid><dc:creator><![CDATA[NanoCraft]]></dc:creator><pubDate>Wed, 03 Oct 2018 19:36:59 GMT</pubDate></item><item><title><![CDATA[Reply to Harvesting from multiple sources within a room on Invalid Date]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="http://screeps.com/forum/uid/2522">@nanocraft</a> I would also recommend adding something like var creepRoom = <a href="http://creep.room.name" rel="nofollow">creep.room.name</a>  and use creepRoom instead of 'W57S44' so that it doesnt break if you move to another room</p>
]]></description><link>http://screeps.com/forum/post/11501</link><guid isPermaLink="true">http://screeps.com/forum/post/11501</guid><dc:creator><![CDATA[ObamaLlama]]></dc:creator><pubDate>Invalid Date</pubDate></item><item><title><![CDATA[Reply to Harvesting from multiple sources within a room on Thu, 04 Oct 2018 14:14:08 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="http://screeps.com/forum/uid/2522">@nanocraft</a> in your else, your if(creep.carry.energy = creep.carryCapacity) is incorrect. It needs to be 2 or 3 equal signs, otherwise you're attempting to assign your carryCapacity to creep.carry.energy.</p>
<p>You're also placing error code of your move command into targets and prospects, but not using that error code.</p>
<p>As for why it's not working, I think your var sources = creep.room.find(FIND_SOURCES); command is limited by scope. It's under the if statement, and I believe that the var will become undefined after that if statement executes. I'm unsure, because I don't use var, I use let, so maybe var is global?</p>
<p>Another thing is that if you call room.find(FIND_SOURCES), sometimes the order in which the sources appear in the array is not always the same...sometimes the source you receive might be rearranged.</p>
]]></description><link>http://screeps.com/forum/post/11508</link><guid isPermaLink="true">http://screeps.com/forum/post/11508</guid><dc:creator><![CDATA[Famine]]></dc:creator><pubDate>Thu, 04 Oct 2018 14:14:08 GMT</pubDate></item><item><title><![CDATA[Reply to Harvesting from multiple sources within a room on Invalid Date]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="http://screeps.com/forum/uid/2439">@famine</a> Thanks for pointing me in the right direction, I used let. The code is a bit-long winded - I am surprised it worked tbh - but it did <img
      src="http://screeps.com/forum/plugins/nodebb-plugin-emoji/emoji/android/1f604.png?v=a1k070tfs06"
      class="not-responsive emoji emoji-android emoji--smile"
      title=":D"
      alt="😄"
    /></p>
<pre><code>run: function(creep) {
let prospect = new RoomPosition(34,4, 'W57S45');
let home = new RoomPosition(16,34, 'W57S44');
    if(creep.memory.prospecting &amp;&amp; (!creep.pos.isNearTo(prospect) || creep.carry.energy === creep.carryCapacity)) {
        creep.memory.prospecting = false;
        creep.say('⛏ seeking');
    }
    if(!creep.memory.prospecting &amp;&amp; (creep.carry.energy &lt; creep.carryCapacity &amp;&amp; creep.pos.isNearTo(prospect))) {
        creep.memory.prospecting = true;
        creep.say('Container');
    }
        if(creep.memory.prospecting) {
   var sources = creep.room.find(FIND_SOURCES);
        if(creep.harvest(sources[0]) == ERR_NOT_IN_RANGE) {
            creep.moveTo(sources[0], {visualizePathStyle: {stroke: '#ffaa00'}});
        }
    }
     if(!creep.memory.prospecting &amp;&amp; creep.carry.energy &lt; creep.carryCapacity) {
        creep.moveTo(prospect)
    }
        else if (!creep.memory.prospecting &amp;&amp; creep.carry.energy === creep.carryCapacity) {
            creep.moveTo(home);
        var targets = creep.pos.findClosestByPath(FIND_STRUCTURES, {
                filter: (s) =&gt; (s.structureType == STRUCTURE_CONTAINER || s.structureType == STRUCTURE_STORAGE) &amp;&amp;
                        s.store.energy &lt; s.storeCapacity
        });
        if(targets) {
            if(creep.transfer(targets, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
                creep.moveTo(targets, {visualizePathStyle: {stroke: '#ffffff'}});
        }
    }
}</code></pre>
]]></description><link>http://screeps.com/forum/post/11517</link><guid isPermaLink="true">http://screeps.com/forum/post/11517</guid><dc:creator><![CDATA[NanoCraft]]></dc:creator><pubDate>Invalid Date</pubDate></item></channel></rss>