Builder don't upgrade walls and ramparts



  • Hello guy's!
    I need help. When i know about screeps i want play in this game but idk js and then i study it. Now i make script and it work i test about 1-2 days in offlane and then try in online. I have error with builder they dont upgrade walls and repair ramparts. 😞
    This cycle to push walls and ramparts:

    for(var id in structuresAll){
        if(structuresAll[id].structureType == "constructedWall"){
            constructedWall.push(structuresAll[id]);
        }
    }
    
    for(var id in structures){
        if(structures[id].structureType=="rampart"){
            constructedWall.push(structures[id]);
        }
    }
    
    allMyStructures.push(constructedWall, storage, extensions);
    
    var increaseHits = true; 
    var needRepair = [];
    var maxHits = 100;
    if (!Memory.maxHits) Memory.maxHits = maxHits;
    else maxHits = Memory.maxHits;
    for (var i = 0; i < constructedWall.length; i++){
        if(constructedWall[i].hits < maxHits) {
            increaseHits = false;
            wallNeedBuild.push(constructedWall[i]);
        }
    }
    if(constructedWall.length > 0){
        if(maxHits < needHits){
            if(increaseHits){
                maxHits+=100;
            }
        }
    }
    if(maxHits == 20000){
        for(var i = 0; i < constructedWall.length; i++){
            if(constructedWall[i].hits < 20000){
                needRepair.push(constructedWall[i]);
            }
        }
    }
    if(spawn.hits < 5000){
        needRepair.push(spawn);
    }
    
    Memory.maxHits = maxHits;
    

    and this part logic of builder's

                    if(builds){
                        creep.moveTo(builds);
                        creep.build(builds);
                    }
                    else{
                        if(needRepair){
                            creep.moveTo(needRepair[0]);
                            creep.repair(needRepair[0])
                        }
                        else if(wallNeedBuild.length > 0){
                            creep.moveTo(wallNeedBuild[0]);
                            creep.repair(wallNeedBuild[0]);
                        }
                    }
    

    Please help me and sry for my bad English!



  • on the english part: you made yourself clear so good job 😛

     

    on the programming part:

    you could much better filter you buildings instead of what your doing right now. il just copy my code for repairing. fully tested and it works.

     

    this code is made out of 3 the same elements:

    is an building going to decay to its destruction? yes? REPAIR NOW (repairnow will be bigger dan 0 so it will do that)

    are there no buildings decaying into destructino? are there buildings with damage? aren't they walls or ramparts? yes? okey good repair them.

    are you done repairing all except walls and rempards? okey good repair the wals and rempards.

    the thing i did with repairwall.lengt - 1 is because the ramparts come last in the list (in my game, you should replace it with 0) and they decay and walls don't. the " - 1" is because list starts with 0 and the length counts from 1.

    && means and

    || means or

    all things bevore or after 'or' must be true so: if (true && false || true) will output trou because after the or it was true. that is why i have 2 times the same checks on each side of the or when checking if the building is an wall or rampart.

     

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

    if (repairitnow.length > 0){
    if (creep.repair(repairitnow[0]) == ERR_NOT_IN_RANGE) {
    creep.moveTo(repairitnow[0]);
    }
    } else {

    var repairit = creep.room.find(FIND_STRUCTURES, {
    filter: (structure) => {
    return (structure.hits < structure.hitsMax && structure.hits > 0 && structure.structureType != STRUCTURE_WALL && structure.structureType != STRUCTURE_RAMPART)
    }
    });

    var repairwall = creep.room.find(FIND_STRUCTURES, {
    filter: (structure) => {
    return (structure.structureType == STRUCTURE_RAMPART && structure.hits < structure.hitsMax && structure.hits > 0 || structure.hits < structure.hitsMax && structure.hits > 0 && structure.structureType == STRUCTURE_WALL)
    }
    });

    if(repairit.length > 0){
    if (creep.repair(repairit[0]) == ERR_NOT_IN_RANGE) {
    creep.moveTo(repairit[0]);
    }
    } else {

    if (repairwall.length > 0){
    if (creep.repair(repairwall[repairwall.length - 1]) == ERR_NOT_IN_RANGE) { //omgekeerde volgorde zodat ramparts eerst gerepaird worden
    creep.moveTo(repairwall[0]);
    }
    } else {
    roleHarvester.run(creep); // so it will alway's will be busy. DO NOT FORGET TO IMPORT(var roleHarvester = require('role.harvester');) IT 
    }
    }
    }

     

    if you have any questions i'l bookmark this post and check it a couple of times next week. 
    Hope i helped Quinten