How is constant CPU cost applied?



  • I didn't find any information on this but when exactly is the const CPU cost applied on the function call or only if it is successfully scheduled?

    Also only for one action or every call that is possible?

    In example for two creep.move() calls on the same creep to change direction in a last minute attempt.


  • int_max

    If the function returns OK then you are charged to CONST cpu cost



  • So that means:

    creep.move(TOP) // blocked ->neglected cost 
    creep.move(RIGHT) // possible -> 0.2 cost
    // More code something happens
    creep.move(DOWN) // possible -> 0.2 cost again
    

    Right? or did I misunderstood something?



  • Sounds about right, except that each type of intent will only cost once for each creep. If your creep moves once and changes it mind in the same tick and moves somewhere else the constant cost is only applied for the first move call. In your example above this means that the constant cost will only be applied to creep.move(RIGHT).

    Also keep in mind that multiple creeps trying to move to the same tile, interacting with the same object or conflicting actions will not conflict with each other inside your code, they will both return OK and the constant cost will be applied multiple times, even if only one of those actions is actually executed.



  • Thx for the info. 😁


  • Culture

    @mrfaul said in How is constant CPU cost applied?:

    So that means:

    creep.move(TOP) // blocked ->neglected cost <<<<<< this is consuming 0.2 anyway as move is returning OK
    creep.move(RIGHT) // possible -> 0.2 cost
    // More code something happens
    creep.move(DOWN) // possible -> 0.2 cost again
    

    Right? or did I misunderstood something?

    The result of this code is 0.6 CPU used. if you get OK back from the API you will have consumed the CPU.

    EDIT:
    I'm wrong. Looked at the code and it's only 0.2: https://github.com/screeps/driver/blob/master/lib/runtime/runtime.js#L148



  • Maybe this should somewhere into the CPU limit doc...
    Apparently even veterans are slightly confused 😂