![screeps atom screeps atom](https://www.codesdope.com/staticroot/images/cs/c-sharp11.png)
Changes to Memory are atomic but changes to Game objects are not.ĮDIT: This possibility occurred to me after reading the documentation for the RawMemory object. Main body of loop goes here, and uses Memory.workQuota to limit the numberĢ.5. Memory.workQuota /= Math.pow( 2, failedTicks ) N failed ticks means the result of this calculation failed to commit N times. However, detecting interrupted cycles is still simple: = function()įailedTicks = Game.time - Memory.time - 1 It becomes more important to improve efficiency when an interrupted cycle is detected, because ignoring it means that the player’s script will be unable to change game state or Memory. If the CPU limit is exceeded, the player’s cycle is interrupted, but neither the scheduled game state changes nor the changes to Memory are committed. The next possibility is that the player’s cycle is atomic.
![screeps atom screeps atom](https://blog.screeps.com/2017/12/auth-tokens/token.png)
This way of managing players’ CPU usage is vulnerable to abuse by infinite loops, and I’m almost certain that this is not the behaviour of Screeps. Main body of loop goes here, and possibly uses skippedTicks to try to do SkippedTicks = Game.time - Memory.time - 1
#Screeps atom code
This can easily be achieved using code like this: = function() CPU limit robust code isn’t strictly necessary in this case, but it would still be useful to detect when the player’s cycle is skipped and possibly start doing things more efficiently.
![screeps atom screeps atom](https://i.stack.imgur.com/GT6bQ.png)
The player’s cycle is never interrupted.Īt one extreme, the player’s memory deserialize, main script execution, and memory re-serialize are never interrupted, and exceeding the CPU limit simply means that the player’s cycle will be skipped on subsequent ticks until the CPU debt is repaid. I’ve considered the following four possibilities: 1. In Screeps, each player’s usage of CPU is limited, but the documentation for this feature doesn’t make the way this is enforced sufficiently clear for writing CPU limit robust code.