Repair every structure fair



  • I want to repair every structure that they have nearly same hitpoints.

    First i tried this:

                    var target_num = 0;
                    var target_durch = 0;
                    for(var i = 0; i < targets.length; i++){
                        target_durch += targets[i].hits;
                    }
                    for(var i = 0; i < targets.length; i++){
                        if(targets[i].hits <= target_durch){
                            target_num = i;
                            return;
                        }
                    }


    I wanted to get the average actual hitpoints from every structure and than set the structure what need to repair first. The Creeps don´t walk with this code. With static target, the creep will only repair one target and a wall with a lot of hitpoints... well you know what i mean.

    I think i made an stupid mistake with the code. Also "traget_durch" means "traget_average"



  • Noticed my mistake...
    I must change "Return" with "break" and also add

    target_durch = target_durch/targets.length;