Search code examples
screeps

How to list my Walls [Screeps]


When I build a new wall using Creep.build(), it creates wall with 1 hit point. Now I am trying to create a creep which repairs these newly constructed walls. But I am not able to figure a good way to list and iterate on these wall objects.

Game.structures doesn't contain these since walls doesn't belong to a player. The only approach I could find was Game.getObjectById(objectId) where id is copy pasted from my game' ui (right panel).


Solution

  • var repairit = creep.room.find(FIND_STRUCTURES, { 
       filter: (structure) => { 
           return ((structure.hits < 5000) && (structure.hits > 0))
       }
    });
    

    this repairs everything in a room, I'll give you a hint towards walls

    structure.structureType == STRUCTURE_WALL