Any way to either rename a spawn or make creeps refer to a spawn by the ID isntead of the name?

  • I'm just starting out, and here's the problem. I have a spawn named "Spawn1" (because I am using slightly modified tutorial code). Unfortunately, a room right next to mine also has an abandoned spawn named "Spawn1". This makes my creeps randomly abandon my spawn for the abandoned one, then do nothing or attempt to upgrade the controller (which I don't need because I am rushing to towers). How to implement either of the things I suggested in the title?

  • How are you getting the spawn in your code? If you’re using Game.spawns, it should only refer to your own spawns.

  • My code seems to be doing just that: if(Game.spawns['Spawn1'].spawning) { var spawningCreep = Game.creeps[Game.spawns['Spawn1']]; Game.spawns['Spawn1'].room.visual.text( '🛠️' + spawningCreep.memory.role, Game.spawns['Spawn1'].pos.x + 1, Game.spawns['Spawn1'].pos.y, {align: 'left', opacity: 0.8}); } What's going wrong, then?

  • I haven't verified your code, but it seems to be trying to print som text next to your spawn. This is probably unrelated to the issue you describe in your original post where you talk about the behaviour of your creeps.

    What do you mean when you say "creeps randomly abandon my spawn". Maybe you can include some code snippets of the related code?

    To answer your original question more specifically. There is a function called getObjectById on the Game object you can use to get any game object by its id. The only limitation is that the game object has to be in a room that is visible to you.

  • Looking at your room, I think your problem is not with the spawn, but with the source. find(), findClosestByRange(), and findClosestByPath() only work for objects in the same room, so if your creep happens to wander into the next room, it will start harvesting from that room's sources. If you weren't trying to harvest from the other source, I'd recommend storing the source's ID in the creep's memory whenever it switches to harvesting mode (see @SandGrainOne's post).

  • I would strongly suggest avoiding spawn names and Game.spawns altogether. Use IDs from the start, it will make life much easier for you later.

    Spawn names are just confusing and pointless. I personally think they should be removed from the game completely. The tutorial would be more useful if it didn't use them.