<?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[Picking up dropped energy]]></title><description><![CDATA[<p>Re: <a href="/forum/topic/1601/question-math-equation-for-distance-energy-on-the-ground">[QUESTION] Math equation for distance &amp; energy on the ground</a></p>
<p>At the current moment, I have a code that looks something like this to pick up dropped energy on the ground:</p>
<pre><code>        if(creep.store.getFreeCapacity() &gt; 0) {
            var sources = creep.room.find(FIND_TOMBSTONES &amp;&amp; FIND_DROPPED_RESOURCES, RESOURCE_ENERGY);
            if(creep.harvest(sources[0]) == ERR_NOT_IN_RANGE) {
                creep.moveTo(sources[0], {visualizePathStyle: {stroke: '#ffaa00'}});
            }
            if(creep.withdraw(sources[0], RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
                creep.moveTo(sources[0], {visualizePathStyle: {stroke: &quot;#ffaa00&quot;}});
            }
        }
        else {
            var targets = creep.room.find(FIND_STRUCTURES, {
                filter: (structure) =&gt; {
                    return (structure.structureType == STRUCTURE_EXTENSION ||
                        structure.structureType == STRUCTURE_SPAWN ||
                        structure.structureType == STRUCTURE_TOWER) &amp;&amp;
                        structure.store.getFreeCapacity(RESOURCE_ENERGY) &gt; 0;
                }
            });
            if(targets.length &gt; 0) {
                if(creep.transfer(targets[0], RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
                    creep.moveTo(targets[0], {visualizePathStyle: {stroke: '#ffffff'}});
                }
            }
        }
</code></pre>
<p>I deliberately didn't put in the unnecessary code. This is put into a creep, who I have named &quot;Collector&quot;, and I have fully linked it as it collects from tombstones but not dropped energy.</p>
]]></description><link>http://screeps.com/forum/topic/3216/picking-up-dropped-energy</link><generator>RSS for Node</generator><lastBuildDate>Tue, 10 Mar 2026 03:30:34 GMT</lastBuildDate><atom:link href="http://screeps.com/forum/topic/3216.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 04 Dec 2021 01:27:41 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Picking up dropped energy on Invalid Date]]></title><description><![CDATA[<p>Re: <a href="/forum/topic/1601/question-math-equation-for-distance-energy-on-the-ground">[QUESTION] Math equation for distance &amp; energy on the ground</a></p>
<p>At the current moment, I have a code that looks something like this to pick up dropped energy on the ground:</p>
<pre><code>        if(creep.store.getFreeCapacity() &gt; 0) {
            var sources = creep.room.find(FIND_TOMBSTONES &amp;&amp; FIND_DROPPED_RESOURCES, RESOURCE_ENERGY);
            if(creep.harvest(sources[0]) == ERR_NOT_IN_RANGE) {
                creep.moveTo(sources[0], {visualizePathStyle: {stroke: '#ffaa00'}});
            }
            if(creep.withdraw(sources[0], RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
                creep.moveTo(sources[0], {visualizePathStyle: {stroke: &quot;#ffaa00&quot;}});
            }
        }
        else {
            var targets = creep.room.find(FIND_STRUCTURES, {
                filter: (structure) =&gt; {
                    return (structure.structureType == STRUCTURE_EXTENSION ||
                        structure.structureType == STRUCTURE_SPAWN ||
                        structure.structureType == STRUCTURE_TOWER) &amp;&amp;
                        structure.store.getFreeCapacity(RESOURCE_ENERGY) &gt; 0;
                }
            });
            if(targets.length &gt; 0) {
                if(creep.transfer(targets[0], RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
                    creep.moveTo(targets[0], {visualizePathStyle: {stroke: '#ffffff'}});
                }
            }
        }
</code></pre>
<p>I deliberately didn't put in the unnecessary code. This is put into a creep, who I have named &quot;Collector&quot;, and I have fully linked it as it collects from tombstones but not dropped energy.</p>
]]></description><link>http://screeps.com/forum/post/16541</link><guid isPermaLink="true">http://screeps.com/forum/post/16541</guid><dc:creator><![CDATA[Tobyers]]></dc:creator><pubDate>Invalid Date</pubDate></item><item><title><![CDATA[Reply to Picking up dropped energy on Invalid Date]]></title><description><![CDATA[<p>Sorry, by unnecessary, I mean the parts that aren't making it do stuff and are linking the creep to my main module etc.</p>
]]></description><link>http://screeps.com/forum/post/16542</link><guid isPermaLink="true">http://screeps.com/forum/post/16542</guid><dc:creator><![CDATA[Tobyers]]></dc:creator><pubDate>Invalid Date</pubDate></item><item><title><![CDATA[Reply to Picking up dropped energy on Invalid Date]]></title><description><![CDATA[<p>As far as I am aware, you can not aggregate find calls in this manner, the parameter for the find accepts ONE OF the find constants, not multiple.</p>
<p>From the API:
<code>
One of the FIND_* constants. </code></p>
<p>You can look at the engine code for it here as well (for private servers but likely how it operations on the MMO as well) <a href="https://github.com/screeps/engine/blob/master/src/game/rooms.js#L584" rel="nofollow">https://github.com/screeps/engine/blob/master/src/game/rooms.js#L584</a></p>
<p>If you want to link the results of multiple find calls into one aggerate array you can combine the two arrays or spread the find calls out over one array, then find as you see fit.</p>
<p>For example you can use the spread operator with two calls to have one array
<code>let sources = [ ...creep.room.find(FIND_TOMBSTONES), ...creep.room.find(FIND_DROPPED_RESOURCES)]</code></p>
<p>Which should result in one array, with objects from both find calls.  You can read about the spread syntax here: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax" rel="nofollow">https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax</a></p>
<p>To be clear as well, for dropped resources you use <code>pickup</code> to gather the energy so even if it was finding dropped resources, harvest/withdraw would not apply (see  API: <a href="https://docs.screeps.com/api/#Creep.pickup" rel="nofollow">https://docs.screeps.com/api/#Creep.pickup</a>)</p>
<p>Hope that helps, elsewise would highly suggest that you check out the Screep's discord.  Its a little more dynamic than the  forums for finding solutions / requesting code assistance.</p>
]]></description><link>http://screeps.com/forum/post/16545</link><guid isPermaLink="true">http://screeps.com/forum/post/16545</guid><dc:creator><![CDATA[Donatzor]]></dc:creator><pubDate>Invalid Date</pubDate></item><item><title><![CDATA[Reply to Picking up dropped energy on Invalid Date]]></title><description><![CDATA[<p>Thanks for the help, I was actually just experimenting random things (I didn't know pickup existed) and I typed in creep.pickup (fancy that) before I had even gotten a response to my question <img
      src="http://screeps.com/forum/plugins/nodebb-plugin-emoji/emoji/android/1f642.png?v=a1k070tfs06"
      class="not-responsive emoji emoji-android emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /> I then figured it out from there!</p>
]]></description><link>http://screeps.com/forum/post/16547</link><guid isPermaLink="true">http://screeps.com/forum/post/16547</guid><dc:creator><![CDATA[Tobyers]]></dc:creator><pubDate>Invalid Date</pubDate></item></channel></rss>