fix previous commit, improve argument page on docs

This commit is contained in:
Mughur
2023-01-30 21:42:46 +02:00
parent 6369ab434b
commit 23199ee705
4 changed files with 47 additions and 14 deletions

View File

@@ -17,7 +17,9 @@ specified in the second argument. The code would look like:
.. code:: javascript
run(args[0], args[1]);
var fileName = args[0];
var threads = args[1];
run(fileName, threads);
And it could be ran from the terminal like:
@@ -28,8 +30,29 @@ In .js / ns2, the above script would look like:
.. code:: javascript
export async function main(ns) {
ns.run(ns.args[0], ns.args[1]);
let fileName = ns.args[0];
let threads = ns.args[1];
ns.run(fileName, threads);
}
It is also possible to get the number of arguments that were passed
into a script using ``args.length``.
If we want to make a script like ``foo.js`` that gets 2 arguments: a string to print
and a number of time to print that string, the code could look like:
.. code:: javascript
export async function main(ns) {
for (let i=0; i<ns.args[1];i++){
ns.tprint(ns.args[0])
}
}
Then we can have another script launch ``foo.js`` with the 2 arguments like:
.. code:: javascript
export async function main(ns) {
ns.exec("foo.js","n00dles",1,"this will be printed twice", 2)
}