creep.say() method takes const CPU



  • creep.say() method takes 0.2 CPU while should take none according to the docs.

    var t0 = Game.getUsedCpu();
    creep.say("something");
    console.log(creep.name + ' ' + (Game.getUsedCpu() - t0));
    


  • I use say() for debugging. Today I started to constantly hit CPU limits even though code did not change for a while. Maybe this is was changed today?



  • This is still not addressed either way. Can we get a definitive answer?



  • This seems to have been fixed partially. I noticed that when creep.say is called, it's sometimes close to 0 cost, and sometimes close to 0.2. Some basic test code show this to be inconsistent even within one tick:

     let buckets = [0,0,0,0,0];
    _.forEach( Game.creeps, function(creep) {
    let time = Game.cpu.getUsed();
    creep.say("0123456789");
    time = Game.cpu.getUsed() - time;
    if(time < 0.05) {
    buckets[0]++;
    } else if(time < 0.10) {
    buckets[1]++;
    } else if(time < 0.15) {
    buckets[2]++;
    } else if(time < 0.20) {
    buckets[3]++;
    } else {
    buckets[4]++;
    }
    });
    console.log(JSON.stringify(buckets));

    Typical result:

    [14,0,0,0,67]

    It's never in between. So it's clear that usually CONST is applied, but sometimes not.


  • Dev Team

    It is a state-changing method, its CPU cost is CONST. This was a mistake in the docs.

    @wicked Regarding your test suite, the reason is creeps being spawned. Creep.say returns ERR_BUSY in their case and doesn’t incur any CPU cost. The CONST CPU cost is charged only when the operation returns the OK result code.



  • Ah! That makes sense. I wish it did take 0 though, since it doesn't give any benefit in the game. It's more like console.log. It's a lot more interesting to watch the creeps when they talk a little bit. The console is not well suited for that.