asterobot:console writes to Asterobot's own log, the one shown in Server > Console and in the terminal Asterobot runs in. It's for a script's diagnostics. To show something to the person watching a bot, use botInfo() and the other functions of asterobot:bot instead: they write to that bot's own console.
import { console, debug, log, info, warn, error } from "asterobot:console";
Scripts have no global console. The console here is an object this module exports, so it has to be imported like the rest.
Exports
| Export | Level of the line |
|---|---|
debug(...values) |
debug |
log(...values) |
info. log is the same function as info. |
info(...values) |
info |
warn(...values) |
warn |
error(...values) |
error |
console |
A frozen object with the same five functions: console.debug(), console.log(), console.info(), console.warn() and console.error() |
Each function takes any number of values, writes them as one line joined with spaces, and returns undefined. They never throw.
info("Route computed in", elapsed, "ms");
console.warn("No zaap found for map", mapId);
Where the lines appear
Lines go to Server > Console and to the terminal. By default, debug lines are left out of both: set Server level to DEBUG on Server > Console to see them there.
In Server > Console, a line doesn't say which bot wrote it. When several bots run scripts, write the bot's name or something that identifies it into the text yourself.
How values print
Values are turned into text the same way as for botInfo(): strings, numbers and booleans print as JavaScript would, a BigInt prints without its n, undefined and null print <nil>, an array prints as [1 2 3], an object as map[name:value], and an Error as map[]. Log String(error) for errors. The table on asterobot:bot has every case.
At a module's top level
Code at the top level of a module also runs while Asterobot reads the package's declarations, and what these functions write at that moment is thrown away. The same code runs again when the script starts, and its lines appear then.
Logging and debugging compares the two consoles and when to use each.
Aucun avis à afficher.