CPU log



  • Explain please i want to know how much CPU used my scripts I made 3 cuts

    console.log("Start = " + Game.cpu.getUsed());
    ..
    console.log("T = " + Game.cpu.getUsed());
    ..
    console.log("Var = " + Game.cpu.getUsed());
    

    I expect next log

    Start = ????
    Var = ????
    T = ????
    .. and repeat
    Start = ????
    Var = ????
    T = ????
    

    But i revived next Logs, why "T" was display without "Start" and "Var" after some cycles

    [4:02:53 PM] [shard1]Start = 0.295728
    [4:02:53 PM] [shard1]Var = 2.758834
    [4:02:53 PM] [shard1]T = 9.199415
    [4:02:55 PM] [shard1]wall repair time! walls.length = 0
    [4:02:55 PM] [shard1]nothing damaged enough to repair
    [4:02:55 PM] [shard1] E = 504/800 Lo = 3/3 HR = 1 UP = 3 BU = 4 DD = 0
    [4:02:57 PM] [shard1]Start = 0.19143
    [4:02:57 PM] [shard1]Var = 2.036277
    [4:02:57 PM] [shard1]T = 7.996323
    [4:02:59 PM] [shard1]T = 5.138256999999999
    [4:03:01 PM] [shard1]T = 4.808282999999999
    [4:03:03 PM] [shard1]T = 5.401028999999999
    [4:03:05 PM] [shard1]T = 5.394404
    [4:03:07 PM] [shard1]T = 4.252630999999999 
    

    Code

    console.log("Start = " + Game.cpu.getUsed());
    require('prototype.spawn')();
    var roleHarvester = require('role.harvester');
    var roleUpgrader = require('role.upgrader');
    var roleBuilder = require('role.builder');
    var roleDamager = require('role.damager');
    var roleTower = require('role.tower');
    var roleWarlord = require('role.warlord');
    var roleMiner = require('role.miner');
    var roleLogist = require('role.logist');
    // setup some minimum numbers for different roles
    var minimumNumberOfHarvesters = 1;
    var minimumNumberOfMiners = 2;
    var minimumNumberOfLogists = 3;
    var minimumNumberOfUpgraders = 3;
    var minimumNumberOfBuilders = 4;
    var minimumNumberOfRepairers = 0;
    var minimumNumberOfWallRepairers = 0;
    var minimumNumberOfDamagers = 0;
    var minimumNumberOfHealers = 0;
    var minimumNumberOfWarlords = 0;
    
    var HOME = 'W38N28';
    var TargetIndex = 'W39N29';
    
    console.log("Var = " + Game.cpu.getUsed());
    
    module.exports.loop = function () {
        // check for memory entries of died creeps by iterating over Memory.creeps
        for (let name in Memory.creeps) {
            // and checking if the creep is still alive
            if (Game.creeps[name] == undefined) {
                // if not, delete the memory entry
                delete Memory.creeps[name];
            }
        }
        // for every creep name in Game.creeps
        for (let name in Game.creeps) {
            // get the creep object
            var creep = Game.creeps[name];
    
            // if creep is harvester, call harvester script
            if (creep.memory.role == 'harvester') {
                roleHarvester.run(creep);
            }
    
            // if warlminer call miner
            else if (creep.memory.role == 'miner') {
                roleMiner.run(creep);
            }
            // if warlminer call miner
            else if (creep.memory.role == 'logist') {
                roleLogist.run(creep);
            }
    
            // if creep is builder, call builder script
            else if (creep.memory.role == 'builder') {
                roleBuilder.run(creep);
            }
            // if creep is repairer, call repairer script
            else if (creep.memory.role == 'repairer') {
                roleRepairer.run(creep);
            }
            // if creep is wallRepairer, call wallRepairer script
            else if (creep.memory.role == 'wallRepairer') {
                roleWallRepairer.run(creep);
            }
            // if creep is longDistanceHarvester, call longDistanceHarvester script
            else if (creep.memory.role == ('longDistanceHarvester')) {
                roleLongDistanceHarvester.run(creep);
            }
            
    
            else if (creep.memory.role == 'damager') {
    //            creep.say('hi');
                roleDamager.run(creep);
            }
            // if warlord
            else if (creep.memory.role == 'warlord') {
                roleWarlord.run(creep);
            }
            
             // if creep is upgrader, call upgrader script
            else if (creep.memory.role == 'upgrader') {
                roleUpgrader.run(creep);
            }
            
            // if creep is upgrader, call upgrader script
            else if (creep.memory.role == 'healer') {
                roleHealer.run(creep);
            }
            
        }
        
    console.log("T = " + Game.cpu.getUsed());    
    
    
    

  • Overlords

    @demos The game will only run code inside the "main loop" every tick. Code before that loop will run only once.

    You'll want to move any "run every tick" to inside the main loop. In this case move your console.log statements. The require statements should stay outside the loop because they only need to load once.

    // This code runs only one time, when you push new code 
    // or a reset happens on the server.
    module.exports.loop = function () {
        // This code runs every tick
    }
    

  • Overlords

    @demos Check out the slack #help channel for quick answers to stuff like this. screeps.slack.com


  • SUN

    @Demos on top of what @kirk explained , what you're seeing are each "worker" process loading your scripts