mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-12-22 14:12:27 +01:00
65cd14e33b
* Add specific types for sleeve tasks * Moved LocationName enum to overall enums file * Add LocationName enum to those provided to player * remove trailing s on CompanyPosNames enum (now CompanyPosName, in line with LocationName) * Also regenerated all ns documentation. This leads to an expected error when checking for generated files, because PRs should not normally touch markdown files. Also leads to a lint failure in generated file bitburner.d.ts * also removed some exporting from NetscriptDefinitions.d.ts for anything that wasn't imported somewhere else.
89 lines
2.8 KiB
Markdown
89 lines
2.8 KiB
Markdown
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||
|
||
[Home](./index.md) > [bitburner](./bitburner.md) > [NS](./bitburner.ns.md) > [print](./bitburner.ns.print.md)
|
||
|
||
## NS.print() method
|
||
|
||
Prints one or more values or variables to the script’s logs.
|
||
|
||
<b>Signature:</b>
|
||
|
||
```typescript
|
||
print(...args: any[]): void;
|
||
```
|
||
|
||
## Parameters
|
||
|
||
| Parameter | Type | Description |
|
||
| --- | --- | --- |
|
||
| args | any\[\] | Value(s) to be printed. |
|
||
|
||
<b>Returns:</b>
|
||
|
||
void
|
||
|
||
## Remarks
|
||
|
||
RAM cost: 0 GB
|
||
|
||
If the argument is a string, you can color code your message by prefixing your string with one of these strings:
|
||
|
||
- `"ERROR"`<!-- -->: The whole string will be printed in red. Use this prefix to indicate that an error has occurred.
|
||
|
||
- `"SUCCESS"`<!-- -->: The whole string will be printed in green, similar to the default theme of the Terminal. Use this prefix to indicate that something is correct.
|
||
|
||
- `"WARN"`<!-- -->: The whole string will be printed in yellow. Use this prefix to indicate that you or a user of your script should be careful of something.
|
||
|
||
- `"INFO"`<!-- -->: The whole string will be printed in purplish blue. Use this prefix to remind yourself or a user of your script of something. Think of this prefix as indicating an FYI (for your information).
|
||
|
||
For custom coloring, use ANSI escape sequences. The examples below use the Unicode escape code `\u001b`<!-- -->. The color coding also works if `\u001b` is replaced with the hexadecimal escape code `\x1b`<!-- -->. The Bash escape code `\e` is not supported. The octal escape code `\033` is not allowed because the game runs JavaScript in strict mode.
|
||
|
||
## Example 1
|
||
|
||
|
||
```ts
|
||
// NS1
|
||
// Default color coding.
|
||
print("ERROR means something's wrong.");
|
||
print("SUCCESS means everything's OK.");
|
||
print("WARN Tread with caution!");
|
||
print("WARNING, warning, danger, danger!");
|
||
print("WARNing! Here be dragons.");
|
||
print("INFO for your I's only (FYI).");
|
||
print("INFOrmation overload!");
|
||
// Custom color coding.
|
||
var cyan = "\u001b[36m";
|
||
var green = "\u001b[32m";
|
||
var red = "\u001b[31m";
|
||
var reset = "\u001b[0m";
|
||
print(red + "Ugh! What a mess." + reset);
|
||
print(green + "Well done!" + reset);
|
||
print(cyan + "ERROR Should this be in red?" + reset);
|
||
tail();
|
||
```
|
||
|
||
## Example 2
|
||
|
||
|
||
```ts
|
||
// NS2
|
||
// Default color coding.
|
||
ns.print("ERROR means something's wrong.");
|
||
ns.print("SUCCESS means everything's OK.");
|
||
ns.print("WARN Tread with caution!");
|
||
ns.print("WARNING, warning, danger, danger!");
|
||
ns.print("WARNing! Here be dragons.");
|
||
ns.print("INFO for your I's only (FYI).");
|
||
ns.print("INFOrmation overload!");
|
||
// Custom color coding.
|
||
const cyan = "\u001b[36m";
|
||
const green = "\u001b[32m";
|
||
const red = "\u001b[31m";
|
||
const reset = "\u001b[0m";
|
||
ns.print(`${red}Ugh! What a mess.${reset}`);
|
||
ns.print(`${green}Well done!${reset}`);
|
||
ns.print(`${cyan}ERROR Should this be in red?${reset}`);
|
||
ns.tail();
|
||
```
|
||
|