mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-12-25 07:32:27 +01:00
49 lines
1.2 KiB
Markdown
49 lines
1.2 KiB
Markdown
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
|
|
|
[Home](./index.md) > [bitburner](./bitburner.md) > [NS](./bitburner.ns.md) > [args](./bitburner.ns.args.md)
|
|
|
|
## NS.args property
|
|
|
|
Arguments passed into the script.
|
|
|
|
<b>Signature:</b>
|
|
|
|
```typescript
|
|
readonly args: (string | number | boolean)[];
|
|
```
|
|
|
|
## Remarks
|
|
|
|
RAM cost: 0 GB
|
|
|
|
Arguments passed into a script can be accessed as a normal array by using the `[]` operator (`args[0]`<!-- -->, `args[1]`<!-- -->, etc...). Arguments can be string, number, or boolean. Use `args.length` to get the number of arguments that were passed into a script.
|
|
|
|
## Example 1
|
|
|
|
`run example.script 7 text true`
|
|
|
|
```js
|
|
// NS1 - example.script
|
|
tprint(args.length) // 3
|
|
tprint(args[0]); // 7 (number)
|
|
tprint(args[1]); // "text" (string)
|
|
tprint(args[2]); // true (boolean)
|
|
tprint(args[3]); // undefined, because only 3 arguments were provided
|
|
```
|
|
|
|
## Example 2
|
|
|
|
`run example.js 7 text true`
|
|
|
|
```js
|
|
// NS2 - example.js
|
|
export async function main(ns) {
|
|
ns.tprint(ns.args.length) // 3
|
|
ns.tprint(ns.args[0]); // 7 (number)
|
|
ns.tprint(ns.args[1]); // "text" (string)
|
|
ns.tprint(ns.args[2]); // true (boolean)
|
|
ns.tprint(ns.args[3]); // undefined, because only 3 arguments were provided
|
|
}
|
|
```
|
|
|