creepCounter problem



  • Hello,
    I have script spawner:

    // UnitsType
    var HARVESTER = [MOVE, WORK, CARRY]; //200E
    module.exports = function (spawn) {
        if (!Memory.creepCount){
            Memory.creepCount = 0;
            console.log("N E W   G A M E");
            console.log("creepCount set on 0");
        }
        var creepName = 'harvester' + Memory.creepCount;
        var canCreate = spawn.canCreateCreep(HARVESTER, creepName);
        if ( canCreate == OK){
            spawn.createCreep(HARVESTER, creepName, {role : 'harvester'});
            Memory.creepCount = Number(Memory.creepCount) +1;
            console.log("creepCount is: " + Memory.creepCount);
        } else {
            //console.log(canCreate);
            if (canCreate == ERR_NAME_EXISTS) console.log(creepName + " exists jet");
            if (canCreate == ERR_INVALID_ARGS) console.log("body desc is wrong");
            if (canCreate == ERR_RCL_NOT_ENOUGH) console.log("control level is low");
        }
    }
    
    Log:
    
    [1:49:30]N E W   G A M E
    [1:49:30]creepCount set on 0
    [1:49:30]creepCount is: 1
    [1:49:55]creepCount is: 2
    [1:50:25]harvester1 exists jet
    [1:50:25]harvester1 exists jet
    [1:50:26]harvester1 exists jet
    [1:50:26]harvester1 exists jet
    [1:50:27]harvester1 exists jet
    

    i really don't know why this doesn't work. Please Help!!!



  • It does not work because nodes the game world is simulated on do not see the same data at the same time. In simple words, data are inconsistent.



  • Thank you very much Actium. Is there some way for save data consistently? I read about globals, but if I understand, globals don't work at multiplayer. The only way that I came to them looping and calculate info every tick, but it drain CPU.



  • It is out of our control to save data consistently. The only thing we can do is to use old "architecture" cause it is not as buggy as new one.



  • Kind of old but I use

    Spawn.prototype.getCreepName = function(role){
    var creepName = role + '_0';
    for(i = 0; i < 9999 ; i++) {
    creepName = role + '_' + i;
    if(Game.creeps[creepName] === undefined || Game.creeps[creepName] === null) break;
    }
    return creepName;
    }