try catch in main.js

This commit is contained in:
dan 2020-11-18 08:30:53 -06:00
parent c03125c5c0
commit ffbabbf8dc

15
main.js
View File

@ -5,6 +5,7 @@ global.verbosity=0
module.exports.loop = function () { module.exports.loop = function () {
console.log("----Start loop for "+ Game.time + '----') console.log("----Start loop for "+ Game.time + '----')
let decrementcounter = Game.time % 30 let decrementcounter = Game.time % 30
try{
for(let name in Game.rooms){ for(let name in Game.rooms){
let myroom=Game.rooms[name] let myroom=Game.rooms[name]
@ -32,15 +33,16 @@ module.exports.loop = function () {
delete myroom.memory.maphits[pos] delete myroom.memory.maphits[pos]
} }
} }
} }} catch(e) {console.log("Error processing rooms: "+ e + " " + e.stack)}
try{
for(let name in Memory.creeps) { for(let name in Memory.creeps) {
if(!Game.creeps[name]) { if(!Game.creeps[name]) {
delete Memory.creeps[name]; delete Memory.creeps[name];
if(global.verbosity>0){ if(global.verbosity>0){
} }
} else { } else {
let creep = Game.creeps[name]
try{ try{
let creep = Game.creeps[name]
if(creep.spawning) return; if(creep.spawning) return;
if(creep.fatigue>0){ if(creep.fatigue>0){
if(creep.room.memory.maphits==undefined){ if(creep.room.memory.maphits==undefined){
@ -64,17 +66,20 @@ module.exports.loop = function () {
require('role.' + creep.memory.role).run(creep) require('role.' + creep.memory.role).run(creep)
//creep.say("TRYING") //creep.say("TRYING")
} catch (e) { } catch (e) {
console.log("creep error " + Game.creeps[name]) creep.say('🦄')
console.log("creep error " + creep.name)
console.log(e) console.log(e)
console.log(e.stack)
} }
} }
//console.log('done running creeps') //console.log('done running creeps')
} }} catch(e) {console.log("Error processing creeps: "+ e.stack)}
try{
let flags = Game.flags let flags = Game.flags
for(let flag in flags){ for(let flag in flags){
//console.log('running flags') //console.log('running flags')
require('flag.' + flag ).run() require('flag.' + flag ).run()
} }} catch(e) {console.log("Error processing flags: "+ e.stack)}
for(let name in Memory.rooms) { for(let name in Memory.rooms) {
// console.log('cleaning up old rooms') // console.log('cleaning up old rooms')
let myroom = Game.rooms[name] let myroom = Game.rooms[name]