Merge branch 'master' into dev

This commit is contained in:
hydroflame 2022-01-09 21:12:10 -05:00 committed by GitHub
commit a53b36ed27
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 21 deletions

@ -106,7 +106,7 @@ Check how much RAM a script requires to run with n threads
**nano [script]** **nano [script]**
Create/Edit a script. The name of the script must end with a valid Create/Edit a script. The name of the script must end with a valid
extension: .script, .js, or .ns extension: .script, or .js
**ps** **ps**

@ -425,7 +425,7 @@ nano
$ nano [filename] $ nano [filename]
Opens up the specified file in the Text Editor. Only scripts (.script, .ns, .js) and Opens up the specified file in the Text Editor. Only scripts (.script, .js) and
text files (.txt) can be edited. If the file does not already exist, then a new text files (.txt) can be edited. If the file does not already exist, then a new
empty file will be created. empty file will be created.
@ -595,7 +595,7 @@ wget
$ wget [url] [target file] $ wget [url] [target file]
Retrieves data from a url and downloads it to a file on the current server. Retrieves data from a url and downloads it to a file on the current server.
The data can only be downloaded to a script (.script, .ns, .js) or a text file The data can only be downloaded to a script (.script, .js) or a text file
(.txt). If the target file already exists, it will be overwritten by this command. (.txt). If the target file already exists, it will be overwritten by this command.
Note that will not be possible to download data from many websites because they Note that will not be possible to download data from many websites because they

@ -7,7 +7,7 @@ autocomplete() Netscript Function
:RAM cost: 0 GB :RAM cost: 0 GB
:param Object data: general data about the game you might want to autocomplete. :param Object data: general data about the game you might want to autocomplete.
:param string[] args: current arguments. Minus `run script.ns` :param string[] args: current arguments. Minus `run script.js`
data is an object with the following properties:: data is an object with the following properties::
@ -34,6 +34,6 @@ autocomplete() Netscript Function
.. code-block:: bash .. code-block:: bash
$ run demo.ns mega\t $ run demo.js mega\t
// results in // results in
$ run demo.ns megacorp $ run demo.js megacorp

@ -21,11 +21,11 @@ As of the time of writing this, a few browsers do not support `dynamic import <h
How to use ns2 How to use ns2
---------------------- ----------------------
Working with ns2 scripts is the same as ns1 scripts. The only difference Working with ns2 scripts is the same as ns1 scripts. The only difference
is that ns2 scripts use the ".ns" or ".js" extension rather than ".script". E.g.:: is that ns2 scripts use the ".js" extension rather than ".script". E.g.::
$ nano foo.ns $ nano foo.js
$ run foo.ns -t 100 arg1 arg2 arg3 $ run foo.js -t 100 arg1 arg2 arg3
exec("foo.ns", "purchasedServer1", "100", "randomArg"); exec("foo.js", "purchasedServer1", "100", "randomArg");
The caveat when using ns2 to write scripts is that your code must be The caveat when using ns2 to write scripts is that your code must be
asynchronous. Furthermore, instead of using the global scope and executing your code asynchronous. Furthermore, instead of using the global scope and executing your code
@ -66,9 +66,9 @@ Here is a summary of all rules you need to follow when writing Netscript JS code
* **Do not write any infinite loops without using a** :code:`sleep` **or one of the timed Netscript functions like** :code:`hack`. Doing so will freeze your game. * **Do not write any infinite loops without using a** :code:`sleep` **or one of the timed Netscript functions like** :code:`hack`. Doing so will freeze your game.
* Any global variable declared in a ns2 script is shared between all instances of that * Any global variable declared in a ns2 script is shared between all instances of that
script. For example, assume you write a script *foo.ns* and declared a global variable like so:: script. For example, assume you write a script *foo.js* and declared a global variable like so::
//foo.ns //foo.js
let globalVariable; let globalVariable;
export async function main(ns) { export async function main(ns) {
@ -79,15 +79,15 @@ Here is a summary of all rules you need to follow when writing Netscript JS code
} }
} }
Then, you ran multiple instances of *foo.ns*:: Then, you ran multiple instances of *foo.js*::
$ run foo.ns 1 $ run foo.js 1
$ run foo.ns 1 2 3 $ run foo.js 1 2 3
$ run foo.ns 1 2 3 4 5 $ run foo.js 1 2 3 4 5
Then all three instances of foo.ns will share the same instance of :code:`globalVariable`. Then all three instances of foo.js will share the same instance of :code:`globalVariable`.
(In this example, the value of :code:`globalVariable` will be set to 5 because the (In this example, the value of :code:`globalVariable` will be set to 5 because the
last instance of *foo.ns* to run has 5 arguments. This means that all three instances of last instance of *foo.js* to run has 5 arguments. This means that all three instances of
the script will repeatedly print the value 5). the script will repeatedly print the value 5).
These global variables can be thought of as `C++ static class members <https://www.tutorialspoint.com/cplusplus/cpp_static_members.htm>`_, These global variables can be thought of as `C++ static class members <https://www.tutorialspoint.com/cplusplus/cpp_static_members.htm>`_,
@ -117,7 +117,7 @@ early-hack-template.script
} }
} }
early-hack-template.ns early-hack-template.js
.. code-block:: javascript .. code-block:: javascript
@ -151,7 +151,7 @@ You may have noticed that every new ns2 file will contains the following comment
* @param {NS} ns * @param {NS} ns
**/ **/
This comment is used to help the text editor autocomplete functions in the Netscript API. You can enabling it by pressing ctrl+space after `ns.` This comment is used to help the text editor autocomplete functions in the Netscript API. You can enable it by pressing ctrl+space after `ns.`
.. image:: autocomplete.png .. image:: autocomplete.png