<?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[Confusing return codes when room is in safeMode]]></title><description><![CDATA[<blockquote>
<p>Minimum information needed:</p>
<p>Which shard is affected?</p>
<ul>
<li>All</li>
</ul>
<p>What happened?</p>
<ul>
<li>When utilizing an some functions, such as <code>attack()</code>, in a room with safe mode, misleading values can be returned (example: attack returns <code>-12</code> <code>ERR_NO_BODYPART</code>)</li>
</ul>
<p>What should have happened?</p>
<ul>
<li>Up for discussion, see below</li>
</ul>
<p>How can we reproduce this?</p>
<ul>
<li>Have a creep attempt to attack a hostile structure/creep in a room with safeMode active</li>
</ul>
</blockquote>
<hr />
<p>While I was going to submit a PR changing the return values for functions like <code>attack()</code> and <code>rangedAttack()</code>, in my opinion <code>rangedMassAttack()</code> raises a problem.</p>
<p>When utilizing attack functions like these in a room that is not yours, and has safe mode active, the return value is <code>ERR_NO_BODYPART</code>.</p>
<p><a href="https://github.com/screeps/engine/blob/9aa2e113355b35789d975bea2ef49aec37c15185/src/game/creeps.js#L604-L605" rel="nofollow">Engine /src/game/creeps.js #604-605</a></p>
<pre><code class="language-js">        if(this.room.controller &amp;&amp; !this.room.controller.my &amp;&amp; this.room.controller.safeMode) {
            return C.ERR_NO_BODYPART;
</code></pre>
<p>When doing something like attempting to <code>withdraw()</code>, the return code is <code>ERR_NOT_OWNER</code> when you were never the owner of the targeted container!</p>
<p><a href="https://github.com/screeps/engine/blob/9aa2e113355b35789d975bea2ef49aec37c15185/src/game/creeps.js#L528-L529" rel="nofollow">Engine /src/game/creeps.js #528-529</a></p>
<pre><code class="language-js">        if(this.room.controller &amp;&amp; !this.room.controller.my &amp;&amp; this.room.controller.safeMode) {
            return C.ERR_NOT_OWNER;
</code></pre>
<p>I feel this is extremely misleading. Granted you should (ideally) not be utilizing these methods in a room with safe mode in the first place (often saves CPU on find checks/pathfinding to avoid these sections entirely, and keeps creeps from exploring into rooms they have no purpose in), but I don't believe it is appropriate to design the API with idealized code in mind. New players may utilize these functions and be confused by this return code (as happened in the Discord today with <code>attack()</code>) I spent a bit of time trying to help this player identify the cause, only for their suggestion of safe mode being active to finally lead me to this issue.</p>
<p>In my opinion, the <em>ideal</em> solution is a new error value: <code>ERR_SAFEMODE_ACTIVE</code> or similar, but <code>ERR_INVALID_TARGET</code> is also acceptable. My reasoning for these two are as follows:</p>
<hr />
<h4>Argument for <code>ERR_SAFEMODE_ACTIVE</code></h4>
<p>I originally wanted to suggest a change to <code>ERR_INVALID_TARGET</code>, but this raises two issues.</p>
<p>Less importantly, it does not make a distinction that safe mode is active. A target that would otherwise be a valid target (eg. a hostile spawn) can become an invalid target the tick that safe mode is activated. This <em>might</em>(?) be confusing for a new developer, but I find this less problematic as players have the responsibility to have an understanding of the game mechanics.</p>
<p>More importantly: <code>ERR_INVALID_TARGET</code> would be an extremely odd return code for functions like <code>rangedMassAttack()</code> which have no target.</p>
<p>Especially for new players, <code>ERR_SAFEMODE_ACTIVE</code> or similar would be extremely clear as to the cause of failure for that action. While these actions are <em>often</em> executing with invalid targets, some actions now (and possibly in the future) are not targeting and thus would not</p>
<hr />
<h4>Argument for <code>ERR_INVALID_TARGET</code></h4>
<p>While less specialized, this does not require the adding of a new constant. It is much more clear than <code>ERR_NO_BODYPART</code>, as that is what is happening: whatever you are doing (even <code>rangedMassAttack()</code>), the target is not valid (since you cannot target anything within a safemode room for these actions.)</p>
<p>There is even precedent for this. When attempting to move into a space where any creep is present while safe mode is active the game returns <code>ERR_INVALID_TARGET</code></p>
<p><a href="https://github.com/screeps/engine/blob/9aa2e113355b35789d975bea2ef49aec37c15185/src/game/creeps.js#L799-L807" rel="nofollow">Engine /src/game/creeps.js #799-807</a></p>
<pre><code class="language-js">        if(_.contains(C.OBSTACLE_OBJECT_TYPES, target.structureType)) {
            if(_.any(objectsInTile)) {
                return C.ERR_INVALID_TARGET;
            }
            const blockingCreeps = (this.room.controller &amp;&amp; this.room.controller.my &amp;&amp; this.room.controller.safeMode) ? myCreepsInTile : creepsInTile;
            if(_.any(blockingCreeps)) {
                return C.ERR_INVALID_TARGET;
            }
        }
</code></pre>
<p>Power creeps also return things such as <code>ERR_INVALID_ARGS</code> or <code>ERR_INVALID_TARGET</code> for certain actions when safe mode is active in the room. <code>usePower()</code>, if it functioned similar to things like <code>attack()</code> on creeps, would return <code>ERR_NO_BODYPART</code> if we were remaining consistent with our return codes.</p>
<p>I hope one of the two will be considered. It is not a pressing change, but either solution should be a minor change to the engine code that would be much clearer and more accurate in my opinion.</p>
]]></description><link>http://screeps.com/forum/topic/3227/confusing-return-codes-when-room-is-in-safemode</link><generator>RSS for Node</generator><lastBuildDate>Wed, 15 Apr 2026 00:34:29 GMT</lastBuildDate><atom:link href="http://screeps.com/forum/topic/3227.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 17 Jan 2022 20:39:15 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Confusing return codes when room is in safeMode on Invalid Date]]></title><description><![CDATA[<blockquote>
<p>Minimum information needed:</p>
<p>Which shard is affected?</p>
<ul>
<li>All</li>
</ul>
<p>What happened?</p>
<ul>
<li>When utilizing an some functions, such as <code>attack()</code>, in a room with safe mode, misleading values can be returned (example: attack returns <code>-12</code> <code>ERR_NO_BODYPART</code>)</li>
</ul>
<p>What should have happened?</p>
<ul>
<li>Up for discussion, see below</li>
</ul>
<p>How can we reproduce this?</p>
<ul>
<li>Have a creep attempt to attack a hostile structure/creep in a room with safeMode active</li>
</ul>
</blockquote>
<hr />
<p>While I was going to submit a PR changing the return values for functions like <code>attack()</code> and <code>rangedAttack()</code>, in my opinion <code>rangedMassAttack()</code> raises a problem.</p>
<p>When utilizing attack functions like these in a room that is not yours, and has safe mode active, the return value is <code>ERR_NO_BODYPART</code>.</p>
<p><a href="https://github.com/screeps/engine/blob/9aa2e113355b35789d975bea2ef49aec37c15185/src/game/creeps.js#L604-L605" rel="nofollow">Engine /src/game/creeps.js #604-605</a></p>
<pre><code class="language-js">        if(this.room.controller &amp;&amp; !this.room.controller.my &amp;&amp; this.room.controller.safeMode) {
            return C.ERR_NO_BODYPART;
</code></pre>
<p>When doing something like attempting to <code>withdraw()</code>, the return code is <code>ERR_NOT_OWNER</code> when you were never the owner of the targeted container!</p>
<p><a href="https://github.com/screeps/engine/blob/9aa2e113355b35789d975bea2ef49aec37c15185/src/game/creeps.js#L528-L529" rel="nofollow">Engine /src/game/creeps.js #528-529</a></p>
<pre><code class="language-js">        if(this.room.controller &amp;&amp; !this.room.controller.my &amp;&amp; this.room.controller.safeMode) {
            return C.ERR_NOT_OWNER;
</code></pre>
<p>I feel this is extremely misleading. Granted you should (ideally) not be utilizing these methods in a room with safe mode in the first place (often saves CPU on find checks/pathfinding to avoid these sections entirely, and keeps creeps from exploring into rooms they have no purpose in), but I don't believe it is appropriate to design the API with idealized code in mind. New players may utilize these functions and be confused by this return code (as happened in the Discord today with <code>attack()</code>) I spent a bit of time trying to help this player identify the cause, only for their suggestion of safe mode being active to finally lead me to this issue.</p>
<p>In my opinion, the <em>ideal</em> solution is a new error value: <code>ERR_SAFEMODE_ACTIVE</code> or similar, but <code>ERR_INVALID_TARGET</code> is also acceptable. My reasoning for these two are as follows:</p>
<hr />
<h4>Argument for <code>ERR_SAFEMODE_ACTIVE</code></h4>
<p>I originally wanted to suggest a change to <code>ERR_INVALID_TARGET</code>, but this raises two issues.</p>
<p>Less importantly, it does not make a distinction that safe mode is active. A target that would otherwise be a valid target (eg. a hostile spawn) can become an invalid target the tick that safe mode is activated. This <em>might</em>(?) be confusing for a new developer, but I find this less problematic as players have the responsibility to have an understanding of the game mechanics.</p>
<p>More importantly: <code>ERR_INVALID_TARGET</code> would be an extremely odd return code for functions like <code>rangedMassAttack()</code> which have no target.</p>
<p>Especially for new players, <code>ERR_SAFEMODE_ACTIVE</code> or similar would be extremely clear as to the cause of failure for that action. While these actions are <em>often</em> executing with invalid targets, some actions now (and possibly in the future) are not targeting and thus would not</p>
<hr />
<h4>Argument for <code>ERR_INVALID_TARGET</code></h4>
<p>While less specialized, this does not require the adding of a new constant. It is much more clear than <code>ERR_NO_BODYPART</code>, as that is what is happening: whatever you are doing (even <code>rangedMassAttack()</code>), the target is not valid (since you cannot target anything within a safemode room for these actions.)</p>
<p>There is even precedent for this. When attempting to move into a space where any creep is present while safe mode is active the game returns <code>ERR_INVALID_TARGET</code></p>
<p><a href="https://github.com/screeps/engine/blob/9aa2e113355b35789d975bea2ef49aec37c15185/src/game/creeps.js#L799-L807" rel="nofollow">Engine /src/game/creeps.js #799-807</a></p>
<pre><code class="language-js">        if(_.contains(C.OBSTACLE_OBJECT_TYPES, target.structureType)) {
            if(_.any(objectsInTile)) {
                return C.ERR_INVALID_TARGET;
            }
            const blockingCreeps = (this.room.controller &amp;&amp; this.room.controller.my &amp;&amp; this.room.controller.safeMode) ? myCreepsInTile : creepsInTile;
            if(_.any(blockingCreeps)) {
                return C.ERR_INVALID_TARGET;
            }
        }
</code></pre>
<p>Power creeps also return things such as <code>ERR_INVALID_ARGS</code> or <code>ERR_INVALID_TARGET</code> for certain actions when safe mode is active in the room. <code>usePower()</code>, if it functioned similar to things like <code>attack()</code> on creeps, would return <code>ERR_NO_BODYPART</code> if we were remaining consistent with our return codes.</p>
<p>I hope one of the two will be considered. It is not a pressing change, but either solution should be a minor change to the engine code that would be much clearer and more accurate in my opinion.</p>
]]></description><link>http://screeps.com/forum/post/16582</link><guid isPermaLink="true">http://screeps.com/forum/post/16582</guid><dc:creator><![CDATA[nascosta]]></dc:creator><pubDate>Invalid Date</pubDate></item></channel></rss>