bitburner-src/markdown/bitburner.ns.printf.md

66 lines
1.4 KiB
Markdown
Raw Normal View History

2022-03-17 21:50:46 +01:00
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [bitburner](./bitburner.md) &gt; [NS](./bitburner.ns.md) &gt; [printf](./bitburner.ns.printf.md)
## NS.printf() method
Prints a formatted string to the scripts logs.
<b>Signature:</b>
```typescript
printf(format: string, ...args: any[]): void;
```
## Parameters
| Parameter | Type | Description |
| --- | --- | --- |
2022-10-10 00:46:13 +02:00
| format | string | Format of the message. |
2022-03-17 21:50:46 +01:00
| args | any\[\] | Value(s) to be printed. |
<b>Returns:</b>
void
## Remarks
RAM cost: 0 GB
2022-10-10 00:46:13 +02:00
- See [print](./bitburner.ns.print.md) for how to add color to your printed strings.
- For more detail, see: https://github.com/alexei/sprintf.js
## Example 1
```ts
// NS1
var name = "Bit";
var age = 4;
printf("My name is %s.", name);
printf("I'm %d seconds old.", age);
printf("My age in binary is %b.", age);
printf("My age in scientific notation is %e.", age);
printf("In %d seconds, I'll be %s.", 6, "Byte");
printf("Am I a nibble? %t", (4 == age));
tail();
```
## Example 2
```ts
// NS2
const name = "Bit";
const age = 4;
ns.printf("My name is %s.", name);
ns.printf("I'm %d seconds old.", age);
ns.printf("My age in binary is %b.", age);
ns.printf("My age in scientific notation is %e.", age);
ns.printf("In %d seconds, I'll be %s.", 6, "Byte");
ns.printf("Am I a nibble? %t", (4 == age));
ns.tail();
```
2022-03-17 21:50:46 +01:00