Skip to content

Instantly share code, notes, and snippets.

@Arcath
Created February 6, 2017 10:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Arcath/0caa58e12428690a7d9f0450695acb78 to your computer and use it in GitHub Desktop.
Save Arcath/0caa58e12428690a7d9f0450695acb78 to your computer and use it in GitHub Desktop.
Screeps Part 12 code examples
// Get the total of all rcls added together (for state change on RCL up)
var rclTotal = 0
_.forEach(Game.rooms, function(room){
if(room.controller){
if(room.controller.my){
rclTotal += room.controller.level
}
}
})
// Use a hash to check if anything in the game has changed
var hashCheck = {
codeRevision: 1, // Increment before deploy to force a new game state
rooms: Object.keys(Game.rooms).length,
creeps: Object.keys(Game.creeps).length,
spawns: Object.keys(Game.spawns).length,
structures: Object.keys(Game.structures).length,
sites: Object.keys(Game.constructionSites).length,
rclTotal: rclTotal
}
var newHash = Utils.hash(hashCheck)
if(Memory.stateCheck != newHash){
// Game state has changed!
Memory.stateCheck = newHash
}else{
// Game state is the same
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment