Screeps: write debug output to console?

Is there a way to get screeps code to print lines in the console (or anywhere) for simple debugging purposes?

+5
source share
4 answers

You can use the standard console.log method for this.

+8
source

To print objects to the console, I use the following:

console.log(JSON.stringify(<myVariable>))

+3
source

I cannot find how to do this in Docs. Had to write something like this:

 module.exports = function () { var log = Memory.log; if(log === null || log === undefined){ log = Memory.log = []; } var parts = ["["+Game.time+"]"]; for(var i in arguments){ parts.push(arguments[i]); } var msg = parts.join(" "); log.push(msg); if(log.length > 10){ log.shift(); } } 

We would be grateful if someone could offer a better solution.

+2
source

Sometimes, when you do console.log, you get useless string representations of objects, something like "[Object]".

If you want to expand an object and check its properties, the easiest solution is to open your browser console. The developers made it so that any .log console in your script also got into the standard browser console. I believe that it works in all major browsers.

0
source

Source: https://habr.com/ru/post/1207448/


All Articles