Skip to content Skip to sidebar Skip to footer

Screeps: Conditions Won't Work - Clueless

So i have been trying this to automatically spawn Creeps in percentage to total living creeps. however when i run this, it just keeps on spawning harvesters, completely ignoring th

Solution 1:

I was doing something similar in my old code:

function allocateResources() {
    var counts = {guard : 0, healer : 0}
    for (var name in Game.creeps) { 
        if (name.indexOf("guard") > -1) {
            counts["guard"]++;
        } else if (name.indexOf("builder") > -1) {
            counts["builder"]++;
        }
        // ...
        counts["total"]++;
    }

    if (counts["guard"] / (counts["total"] + 1) < 0.51) {
       spawnCreep("guard"); 
    } else if (counts["builder"] / (counts["total"] + 1) < 0.34) {
       spawnCreep("builder");
    } 
    // ...
}

You should make sure that you avoid division by zero, perhaps that's the bug for you.


Post a Comment for "Screeps: Conditions Won't Work - Clueless"