<?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[Claiming a new room, please help]]></title><description><![CDATA[<p>I have recently reached GCL 2 and am trying to claim a new room. i have been trying to use<br />
creep.moveTo(new RoomPosition(47, 25, 'E15S5'));<br />
however it is giving me error  messages that make no sense.
please give me a code that will tell my creep to move to a specific room, go to the controler in that room, and claim it</p>
]]></description><link>http://screeps.com/forum/topic/2390/claiming-a-new-room-please-help</link><generator>RSS for Node</generator><lastBuildDate>Tue, 18 Aug 2026 14:55:48 GMT</lastBuildDate><atom:link href="http://screeps.com/forum/topic/2390.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 11 Oct 2018 14:30:14 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Claiming a new room, please help on Invalid Date]]></title><description><![CDATA[<p>I have recently reached GCL 2 and am trying to claim a new room. i have been trying to use<br />
creep.moveTo(new RoomPosition(47, 25, 'E15S5'));<br />
however it is giving me error  messages that make no sense.
please give me a code that will tell my creep to move to a specific room, go to the controler in that room, and claim it</p>
]]></description><link>http://screeps.com/forum/post/11594</link><guid isPermaLink="true">http://screeps.com/forum/post/11594</guid><dc:creator><![CDATA[UncreativeUsername]]></dc:creator><pubDate>Invalid Date</pubDate></item><item><title><![CDATA[Reply to Claiming a new room, please help on Invalid Date]]></title><description><![CDATA[<p>Hello <a class="plugin-mentions-user plugin-mentions-a" href="http://screeps.com/forum/uid/2530">@UncreativeUsername</a></p>
<p>I'm pretty new too, so my approach was to stablish flag colors for different purposes. This way, you can do something like...</p>
<pre><code>if(creep.room != flag.room){
    creep.moveTo(flag);
}else{
    creep.claim(creep.room.controller);
}
</code></pre>
<p>Hope it helps, and if you still want me to give you the code i use, just ask for it.</p>
]]></description><link>http://screeps.com/forum/post/11596</link><guid isPermaLink="true">http://screeps.com/forum/post/11596</guid><dc:creator><![CDATA[Calfa]]></dc:creator><pubDate>Invalid Date</pubDate></item><item><title><![CDATA[Reply to Claiming a new room, please help on Thu, 11 Oct 2018 16:50:51 GMT]]></title><description><![CDATA[<p>so creeps can see flags in other rooms? or do you place the flag on the border of the first room so the creep goes into the second room?</p>
<p>I would love your code, but I also will want to know how it works, so if you are willing to give it to me expect potential questions on the how and why of the code.</p>
]]></description><link>http://screeps.com/forum/post/11597</link><guid isPermaLink="true">http://screeps.com/forum/post/11597</guid><dc:creator><![CDATA[UncreativeUsername]]></dc:creator><pubDate>Thu, 11 Oct 2018 16:50:51 GMT</pubDate></item><item><title><![CDATA[Reply to Claiming a new room, please help on Thu, 11 Oct 2018 17:07:04 GMT]]></title><description><![CDATA[<p>Yes, creeps can directly <code>moveTo(flag)</code> even if that flag is in another room.</p>
<p>Here is the code for my &quot;flagReserver&quot;. It's obvious purpose is to reserve a room controller.</p>
<pre><code>//Assign new flag will execute if i remove the flag creep belongs to    
const AssignNewFlag = require('routines.assignNewFlag');

var roleFlagReserver = {

    run: function(creep) {

        let flag = Game.flags[creep.memory.targetFlag];

        let ctrl = creep.room.controller;
        
        //If creep has a flag    
        if(flag &amp;&amp; flag.color == COLOR_PURPLE &amp;&amp; flag.secondaryColor == COLOR_PURPLE ){

            //If they are in the same room
            if(creep.room == flag.room){

                let reserveResult = creep.reserveController(ctrl);

                if(reserveResult == ERR_NOT_IN_RANGE){

                    creep.moveTo(ctrl, {visualizePathStyle: {stroke: '#cc00cc'}});

                }

            }else{

                creep.moveTo(flag, {visualizePathStyle: {stroke: '#cc00cc'}});

            }

        }else{

            AssignNewFlag.run(creep, COLOR_PURPLE, COLOR_PURPLE);

        }

    }

};
module.exports = roleFlagReserver;
</code></pre>
<p>Now i realize that rather than having the creep trying to reserve each tick, i should check <code>creep.pos.isNearTo(ctrl) </code> and then start reserving, but as an example i think it's ok.</p>
<p>Feel free to ask whatever you need.</p>
<p>This is the code for my &quot;flagManager&quot;:</p>
<pre><code>const CreateCreep = require('routines.spawnCreep');
const Show = require('show.info');

var FlagManager = {

    run: function(flag){
    
        let desiredMinions = 0;
        let currentMinions = 0;
        let ticksToDie = 100;



        if(Number.isInteger(parseInt(flag.name))){
            desiredMinions = parseInt(flag.name);
            flag.memory.desiredMinions = desiredMinions;
        }else{
            console.log('Flag &quot;'+flag.name+'&quot; at room '+flag.room.name+' has a wrong name!');
        }
    

        for(let i in Game.creeps){

            let creep = Game.creeps[i];
            if(creep.memory.targetFlag == flag.name &amp;&amp; creep.ticksToLive &gt; ticksToDie ){
        
                currentMinions++;
            }
        }
        flag.memory.currentMinions = currentMinions;
        if(SHOW_FLAG_INFO){
            Show.assignedMinions(flag, desiredMinions, currentMinions);
        }


        if(currentMinions &lt; desiredMinions){
        
            let minDist = 10;
            let distance = 0;
            let targetSpawn = null;

            if(_.isString(flag.memory.targetRoom)){

                targetSpawn = Game.getObjectById(Game.rooms[flag.memory.targetRoom].memory.spawns[0].id);

            }else{
                for (let i in Game.rooms){

                    if(Game.rooms[i].controller.my){
    
                        distance = Game.map.getRoomLinearDistance(flag.pos.roomName, Game.rooms[i].name, false);
                        if(distance &lt; minDist &amp;&amp; null!=Game.rooms[i].memory.spawns){
                            minDist = distance;
                            flag.memory.targetRoom = Game.rooms[i].name;
    
                            targetSpawn = Game.getObjectById(Game.rooms[flag.memory.targetRoom].memory.spawns[0].id);
                            break;
                        }
                    }
                }
        }    


            if(targetSpawn){

                let extendedAttributes = {};
                let creepRole = '';
            
                switch(flag.color){
//RESERVE
                    case COLOR_PURPLE:
                        if(flag.secondaryColor == COLOR_PURPLE){
                            creepRole = 'flagReserver';
                            extendedAttributes = {myRoom: flag.memory.targetRoom,   mySpawn: targetSpawn.name,      targetFlag: flag.name.toString()    };
                        }else if(flag.secondaryColor == COLOR_WHITE){
                            creepRole = 'flagClaimer';
                            extendedAttributes = {myRoom: flag.memory.targetRoom,   mySpawn: targetSpawn.name,      targetFlag: flag.name.toString()    };
                        }
                    break;
//HARVEST
                    case COLOR_BLUE:
                        if(flag.secondaryColor == COLOR_BLUE){    
                            creepRole = 'flagHarvester';
                            extendedAttributes = {myRoom: flag.memory.targetRoom,   mySpawn: targetSpawn.name,      targetFlag: flag.name.toString(),       harvesting: true    };
                        }
                    break;
//BUILD/ASSIST NEW ROOM
                    case COLOR_GREEN:
                        if(flag.secondaryColor == COLOR_GREEN){    
                            creepRole = 'flagBuilder';
                            extendedAttributes = {myRoom: flag.memory.targetRoom,   mySpawn: targetSpawn.name,      targetFlag: flag.name.toString(),       harvesting : true   };
                        }else if(flag.secondaryColor == COLOR_WHITE){    
                            creepRole = 'flagRepairer';
                            extendedAttributes = {myRoom: flag.memory.targetRoom,   mySpawn: targetSpawn.name,      targetFlag: flag.name.toString(),       harvesting : true   };
                        }
                    break;
                
                    default:    break;
                }
            
                let targetRoom = Game.rooms[flag.memory.targetRoom];
                let createResult = CreateCreep.run(targetRoom, creepRole, extendedAttributes);
            }
        }
    }
};

module.exports = FlagManager;</code></pre>
]]></description><link>http://screeps.com/forum/post/11599</link><guid isPermaLink="true">http://screeps.com/forum/post/11599</guid><dc:creator><![CDATA[Calfa]]></dc:creator><pubDate>Thu, 11 Oct 2018 17:07:04 GMT</pubDate></item><item><title><![CDATA[Reply to Claiming a new room, please help on Thu, 11 Oct 2018 17:12:39 GMT]]></title><description><![CDATA[<p>const AssignNewFlag = require('routines.assignNewFlag');</p>
<p>does this assign the creep to a flag? how do you control wich flag if you have multiple flags?</p>
<p>edit: nvm i found at the bottom that you assign by color.</p>
]]></description><link>http://screeps.com/forum/post/11600</link><guid isPermaLink="true">http://screeps.com/forum/post/11600</guid><dc:creator><![CDATA[UncreativeUsername]]></dc:creator><pubDate>Thu, 11 Oct 2018 17:12:39 GMT</pubDate></item><item><title><![CDATA[Reply to Claiming a new room, please help on Invalid Date]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="http://screeps.com/forum/uid/2530">@uncreativeusername</a></p>
<p>Creeps are created from &quot;flagManager&quot; and they already know which is their flag when they born. However, assignNewFlag is used in case a creep can't find his flag because i removed it.</p>
<p>Here is &quot;assignNewFlag&quot;</p>
<pre><code>module.exports = {

    run: function(creep, flagColor,flagSecColor){
        
        //Assign the creep to a flag which &quot;needs&quot; it
        
            for(let i in Game.flags){
                let thatFlag = Game.flags[i];
                if(thatFlag.color == flagColor &amp;&amp; thatFlag.secondaryColor == flagSecColor &amp;&amp; Game.flags[i].memory.desiredMinions &gt; Game.flags[i].memory.currentMinions){
                    creep.memory.targetFlag = thatFlag.name;
                }
            }
        
        //If there aren't, just assign to a flag of the right color
        
            if(!(Game.flags[creep.memory.targetFlag] &amp;&amp; Game.flags[creep.memory.targetFlag].color == flagColor &amp;&amp; Game.flags[creep.memory.targetFlag].secondaryColor == flagSecColor)){
                for(let i in Game.flags){
                    let thatFlag = Game.flags[i];
                    if(thatFlag.color == flagColor &amp;&amp; thatFlag.secondaryColor == flagSecColor){
                        creep.memory.targetFlag = thatFlag.name;
                    }
                }
            }
            
        //If i can't find the right flag after all, send creep back to the spawn it was born

            if(!Game.flags[creep.memory.targetFlag]){
                creep.memory.targetFlag = null;
                if(!creep.fatige){
                    creep.moveTo(Game.spawns[creep.memory.mySpawn], {reusePath: REUSE_PATH, visualizePathStyle: {stroke: '#ffffff'}});
                }
            }
    }

};</code></pre>
]]></description><link>http://screeps.com/forum/post/11601</link><guid isPermaLink="true">http://screeps.com/forum/post/11601</guid><dc:creator><![CDATA[Calfa]]></dc:creator><pubDate>Invalid Date</pubDate></item><item><title><![CDATA[Reply to Claiming a new room, please help on Invalid Date]]></title><description><![CDATA[<p>so i am guessing flagmanager is its own module?</p>
]]></description><link>http://screeps.com/forum/post/11602</link><guid isPermaLink="true">http://screeps.com/forum/post/11602</guid><dc:creator><![CDATA[UncreativeUsername]]></dc:creator><pubDate>Invalid Date</pubDate></item><item><title><![CDATA[Reply to Claiming a new room, please help on Invalid Date]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="http://screeps.com/forum/uid/2530">@uncreativeusername</a> Yes, each piece of code i posted has it's own module</p>
]]></description><link>http://screeps.com/forum/post/11603</link><guid isPermaLink="true">http://screeps.com/forum/post/11603</guid><dc:creator><![CDATA[Calfa]]></dc:creator><pubDate>Invalid Date</pubDate></item><item><title><![CDATA[Reply to Claiming a new room, please help on Thu, 11 Oct 2018 17:35:11 GMT]]></title><description><![CDATA[<p>so, i I just want one of my roles to involve flags, because my other roles are already working, how could I tell the one role to be assigned to a flag? like, without using assign new flag, and encorperating it into the same module?</p>
]]></description><link>http://screeps.com/forum/post/11604</link><guid isPermaLink="true">http://screeps.com/forum/post/11604</guid><dc:creator><![CDATA[UncreativeUsername]]></dc:creator><pubDate>Thu, 11 Oct 2018 17:35:11 GMT</pubDate></item><item><title><![CDATA[Reply to Claiming a new room, please help on Thu, 11 Oct 2018 17:31:07 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="http://screeps.com/forum/uid/2530">@uncreativeusername</a> The way i create the creeps involving flags is by using the name of the flag. It must be an integer (could be 1, 01, 001....2....), and it means the number of creeps you want for that flag.</p>
<p>You can take my &quot;flagManager&quot; code and reduce the switch statement so it works only with 1 color, and if you need in the future it'll be pretty easy to add more.</p>
<p>Then, from the main module...</p>
<pre><code>for(let i in Game.flags){
    let thisFlag = Game.flags[i];
    FlagManager.run(thisFlag);
}
</code></pre>
<p>You don't really need to use &quot;assignNewFlag&quot; as long as you make sure the flag exists as long as creep does.</p>
]]></description><link>http://screeps.com/forum/post/11605</link><guid isPermaLink="true">http://screeps.com/forum/post/11605</guid><dc:creator><![CDATA[Calfa]]></dc:creator><pubDate>Thu, 11 Oct 2018 17:31:07 GMT</pubDate></item><item><title><![CDATA[Reply to Claiming a new room, please help on Thu, 11 Oct 2018 17:36:04 GMT]]></title><description><![CDATA[<p>or, could I do somthing like this in the module:</p>
<p>var roleclaimer = {</p>
<p>run: function(creep) {</p>
<pre><code>let flag = Game.flags[creep.memory.targetFlag];

let ctrl = creep.room.controller;

if(flag){
    
    if(creep.room == flag.room){

        let claimResult = creep.claimController(ctrl);

        if(claimResult == ERR_NOT_IN_RANGE){

            creep.moveTo(ctrl, {visualizePathStyle: {stroke: '#cc00cc'}});

        }

    }
    else{

        creep.moveTo(flag, {visualizePathStyle: {stroke: '#cc00cc'}});

    }

}
</code></pre>
<p>}
}; module.exports = roleclaimer;</p>
<p>and then, since i will only use each creep once, spawn the creep like this :
<code>Game.spawns['S1'].spawnCreep( [CLAIM, MOVE], 'Claimer1', { memory: { role: 'claimer' } {targetFlag: 'flag1'} );</code></p>
]]></description><link>http://screeps.com/forum/post/11606</link><guid isPermaLink="true">http://screeps.com/forum/post/11606</guid><dc:creator><![CDATA[UncreativeUsername]]></dc:creator><pubDate>Thu, 11 Oct 2018 17:36:04 GMT</pubDate></item><item><title><![CDATA[Reply to Claiming a new room, please help on Thu, 11 Oct 2018 17:40:10 GMT]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="http://screeps.com/forum/uid/2530">@uncreativeusername</a> Yes, despite possible errors on the code i think that should do it. I also started with a simpler code, but it became more and more complex as i detected exceptions, errors and undesired behaviours.</p>
<p>I recommend you to do it with a new role whose body is just [MOVE] and see what happens, so you don't bankrupt while you solve it xDD</p>
]]></description><link>http://screeps.com/forum/post/11607</link><guid isPermaLink="true">http://screeps.com/forum/post/11607</guid><dc:creator><![CDATA[Calfa]]></dc:creator><pubDate>Thu, 11 Oct 2018 17:40:10 GMT</pubDate></item><item><title><![CDATA[Reply to Claiming a new room, please help on Invalid Date]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="http://screeps.com/forum/uid/2533">@Calfa</a> thank you this is a huge help.</p>
]]></description><link>http://screeps.com/forum/post/11608</link><guid isPermaLink="true">http://screeps.com/forum/post/11608</guid><dc:creator><![CDATA[UncreativeUsername]]></dc:creator><pubDate>Invalid Date</pubDate></item><item><title><![CDATA[Reply to Claiming a new room, please help on Invalid Date]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="http://screeps.com/forum/uid/2530">@uncreativeusername</a> A big pleasure to help. Even more considering the amount of knowledge and help i got from this forum.</p>
]]></description><link>http://screeps.com/forum/post/11609</link><guid isPermaLink="true">http://screeps.com/forum/post/11609</guid><dc:creator><![CDATA[Calfa]]></dc:creator><pubDate>Invalid Date</pubDate></item><item><title><![CDATA[Reply to Claiming a new room, please help on Invalid Date]]></title><description><![CDATA[<p>confirmed, role.claimer is functional!</p>
]]></description><link>http://screeps.com/forum/post/11611</link><guid isPermaLink="true">http://screeps.com/forum/post/11611</guid><dc:creator><![CDATA[UncreativeUsername]]></dc:creator><pubDate>Invalid Date</pubDate></item></channel></rss>