mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-22 01:03:01 +02:00
V0.35.0. Adding netscript_tests in game testbench.
This commit is contained in:
+12
-12
@@ -25,27 +25,27 @@ a value to these.
|
||||
|
||||
Note that these must be called on an element inside the *hacknetnodes* array, not the array itself.
|
||||
|
||||
.. js:function:: hacknetnodes[i].level
|
||||
.. js:attribute:: hacknetnodes[i].level
|
||||
|
||||
Returns the level of the corresponding Hacknet Node
|
||||
|
||||
.. js:function:: hacknetnodes[i].ram
|
||||
.. js:attribute:: hacknetnodes[i].ram
|
||||
|
||||
Returns the amount of RAM on the corresponding Hacknet Node
|
||||
|
||||
.. js:function:: hacknetnodes[i].cores
|
||||
.. js:attribute:: hacknetnodes[i].cores
|
||||
|
||||
Returns the number of cores on the corresponding Hacknet Node
|
||||
|
||||
.. js:function:: hacknetnodes[i].totalMoneyGenerated
|
||||
.. js:attribute:: hacknetnodes[i].totalMoneyGenerated
|
||||
|
||||
Returns the total amount of money that the corresponding Hacknet Node has earned
|
||||
|
||||
.. js:function:: hacknetnodes[i].onlineTimeSeconds
|
||||
.. js:attribute:: hacknetnodes[i].onlineTimeSeconds
|
||||
|
||||
Returns the total amount of time (in seconds) that the corresponding Hacknet Node has existed
|
||||
|
||||
.. js:function:: hacknetnodes[i].moneyGainRatePerSecond
|
||||
.. js:attribute:: hacknetnodes[i].moneyGainRatePerSecond
|
||||
|
||||
Returns the amount of income that the corresponding Hacknet Node earns
|
||||
|
||||
@@ -57,7 +57,7 @@ The following is a list of supported functions/methods for a Hacknet Node object
|
||||
Note that these must be called on an element inside the *hacknetnodes* array, not the
|
||||
array itself.
|
||||
|
||||
.. js:function:: hacknetnodes[i].upgradeLevel(n);
|
||||
.. js:method:: hacknetnodes[i].upgradeLevel(n)
|
||||
|
||||
:param number n: Number of levels to upgrade. Must be positive. Rounded to nearest integer
|
||||
|
||||
@@ -65,27 +65,27 @@ array itself.
|
||||
Hacknet Node's level is successfully upgraded *n* times or up to the max level (200), and false
|
||||
otherwise.
|
||||
|
||||
.. js:function:: hacknetnodes[i].upgradeRam()
|
||||
.. js:method:: hacknetnodes[i].upgradeRam()
|
||||
|
||||
Tries to upgrade the amount of RAM on the corresponding Hacknet Node. Returns true if the RAM is
|
||||
successfully upgraded and false otherwise.
|
||||
|
||||
.. js:function:: hacknetnodes[i].upgradeCore()
|
||||
.. js:method:: hacknetnodes[i].upgradeCore()
|
||||
|
||||
Tries to purchase an additional core for the corresponding Hacknet Node. Returns true if the
|
||||
additional core is successfully purchased, and false otherwise.
|
||||
|
||||
.. js:function:: hacknetnodes[i].getLevelUpgradeCost(n);
|
||||
.. js:method:: hacknetnodes[i].getLevelUpgradeCost(n)
|
||||
|
||||
:param number n: Number of levels to upgrade. Must be positive. Rounded to nearest integer
|
||||
|
||||
Returns the cost of upgrading the specified Hacknet Node by *n* levels
|
||||
|
||||
.. js:function:: hacknetnodes[i].getRamUpgradeCost()
|
||||
.. js:method:: hacknetnodes[i].getRamUpgradeCost()
|
||||
|
||||
Returns the cost of upgrading the RAM of the specified Hacknet Node. Upgrading a Node's RAM doubles it.
|
||||
|
||||
.. js:function:: hacknetnodes[i].getCoreUpgradeCost()
|
||||
.. js:method:: hacknetnodes[i].getCoreUpgradeCost()
|
||||
|
||||
Returns the cost of upgrading the number of cores of the specified Hacknet Node. Upgrading a Node's
|
||||
number of cores adds one additional core.
|
||||
|
||||
+139
@@ -1,6 +1,135 @@
|
||||
Netscript Miscellaneous
|
||||
=======================
|
||||
|
||||
Netscript Ports
|
||||
---------------
|
||||
Netscript ports are endpoints that can be used to communicate between scripts.
|
||||
A port is implemented as a sort of serialized queue, where you can only write
|
||||
and read one element at a time from the port. When you read data from a port,
|
||||
the element that is read is removed from the port.
|
||||
|
||||
The :js:func:`read`, :js:func:`write`, :js:func:`clear`, and :js:func:`peek`
|
||||
Netscript functions can be used to interact with ports.
|
||||
|
||||
Right now, there are only 20 ports for Netscript, denoted by the number 1
|
||||
through 20. When using the functions above, the ports are specified
|
||||
by passing the number as the first argument.
|
||||
|
||||
IMPORTANT: The data inside ports are not saved! This means if you close and
|
||||
re-open the game, or reload the page then you will lose all of the data in
|
||||
the ports!
|
||||
|
||||
**Example Usage**
|
||||
|
||||
Here's a brief example of how ports work. For the sake of simplicity we'll only deal with port 1.
|
||||
|
||||
Let's assume Port 1 starts out empty (no data inside). We'll represent the port as such::
|
||||
|
||||
[]
|
||||
|
||||
Now assume we ran the following simple script::
|
||||
|
||||
for (i = 0; i < 10; ++i) {
|
||||
write(1, i); //Writes the value of i to port 1
|
||||
}
|
||||
|
||||
After this script executes, our script will contain every number from 0 through 9, as so::
|
||||
|
||||
[0, 1, 2, 3, 4, 5, 6, 7 , 8, 9]
|
||||
|
||||
Then, assume we run the following script::
|
||||
|
||||
for (i = 0; i < 3; ++i) {
|
||||
print(read(1)); //Reads a value from port 1 and then prints it
|
||||
}
|
||||
|
||||
This script above will read the first three values from port 1 and then print them to the script's log. The log will end up looking like::
|
||||
|
||||
0
|
||||
1
|
||||
2
|
||||
|
||||
And the data in port 1 will look like::
|
||||
|
||||
[3, 4, 5, 6, 7, 8, 9]
|
||||
|
||||
**Port Handles**
|
||||
|
||||
The :js:func:`getPortHandle` Netscript function can be used to get a handle to a Netscript Port.
|
||||
This handle allows you to access several new port-related functions and the
|
||||
port's underlying data structure, which is just a Javascript array. The functions are:
|
||||
|
||||
.. js:method:: NetscriptPort.write(data)
|
||||
|
||||
:param data: Data to write to the port
|
||||
:returns: If the port is full, the item that is removed from the port is returned.
|
||||
Otherwise, null is returned.
|
||||
|
||||
Writes `data` to the port. Works the same as the Netscript function `write`.
|
||||
|
||||
.. js:method:: NetscriptPort.tryWrite(data)
|
||||
|
||||
:param data: Data to try to write to the port
|
||||
:returns: True if the data is successfully written to the port, and false otherwise.
|
||||
|
||||
Attempts to write `data` to the Netscript port. If the port is full, the data will
|
||||
not be written. Otherwise, the data will be written normally.
|
||||
|
||||
.. js::method:: NetscriptPort.read()
|
||||
|
||||
:returns: The data read from the port. If the port is empty, "NULL PORT DATA" is returned
|
||||
|
||||
Removes and returns the first element from the port.
|
||||
Works the same as the Netscript function `read`
|
||||
|
||||
.. js::method:: NetscriptPort.peek()
|
||||
|
||||
:returns: The first element in the port, or "NULL PORT DATA" if the port is empty.
|
||||
|
||||
Returns the first element in the port, but does not remove it.
|
||||
Works the same as the Netscript function `peek`
|
||||
|
||||
.. js:method:: NetscriptPort.full()
|
||||
|
||||
:returns: True if the Netscript Port is full, and false otherwise
|
||||
|
||||
.. js:method:: NetscriptPort.empty()
|
||||
|
||||
:returns: True if the Netscript Port is empty, and false otherwise
|
||||
|
||||
.. js:method:: NetscriptPort.clear()
|
||||
|
||||
Clears all data from the port. Works the same as the Netscript function `clear`
|
||||
|
||||
.. js:attribute:: NetscriptPort.data
|
||||
|
||||
The Netscript port underlying data structure, which is just a Javascript array. All
|
||||
valid Javascript Array methods can be called on this.
|
||||
|
||||
Port Handle Example::
|
||||
|
||||
port = getPortHandle(5);
|
||||
back = port.data.pop(); //Get and remove last element in port
|
||||
|
||||
//Remove an element from the port
|
||||
i = port.data.findIndex("foo");
|
||||
if (i != -1) {
|
||||
port.data.slice(i, 1);
|
||||
}
|
||||
|
||||
//Wait for port data before reading
|
||||
while(port.empty()) {
|
||||
sleep(10000);
|
||||
}
|
||||
res = port.read();
|
||||
|
||||
//Wait for there to be room in a port before writing
|
||||
while (!port.tryWrite(5)) {
|
||||
sleep(5000);
|
||||
}
|
||||
|
||||
//Successfully wrote to port!
|
||||
|
||||
|
||||
Comments
|
||||
--------
|
||||
@@ -35,3 +164,13 @@ However, since the 'new' operator does not work in Netscript, only the Date modu
|
||||
Example::
|
||||
|
||||
time = Date.now();
|
||||
|
||||
Javascript Number Module
|
||||
------------------------
|
||||
|
||||
The `Javascript Number module <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number>`_ is supported in Netscript.
|
||||
|
||||
Example::
|
||||
|
||||
tprint(Number.isInteger(1)); //True
|
||||
tprint(Number.isInteger(1.534059)); //False
|
||||
|
||||
Vendored
+10
-28
@@ -229,41 +229,19 @@
|
||||
<td style="width: 33%; vertical-align: top;"><ul>
|
||||
<li><a href="netscriptfunctions.html#hack">hack() (built-in function)</a>
|
||||
</li>
|
||||
<li><a href="netscripthacknetnodeapi.html#hacknetnodes[i].cores">hacknetnodes[i].cores() (hacknetnodes[i] method)</a>
|
||||
<li><a href="netscripthacknetnodeapi.html#hacknetnodes[i].cores">hacknetnodes[i].cores (hacknetnodes[i] attribute)</a>
|
||||
</li>
|
||||
<li><a href="netscripthacknetnodeapi.html#hacknetnodes[i].getCoreUpgradeCost">hacknetnodes[i].getCoreUpgradeCost() (hacknetnodes[i] method)</a>
|
||||
<li><a href="netscripthacknetnodeapi.html#hacknetnodes[i].level">hacknetnodes[i].level (hacknetnodes[i] attribute)</a>
|
||||
</li>
|
||||
<li>
|
||||
hacknetnodes[i].getLevelUpgradeCost(n)
|
||||
|
||||
<ul>
|
||||
<li><a href="netscripthacknetnodeapi.html#hacknetnodes[i].getLevelUpgradeCost(n);">() (hacknetnodes[i] method)</a>
|
||||
</li>
|
||||
</ul></li>
|
||||
<li><a href="netscripthacknetnodeapi.html#hacknetnodes[i].getRamUpgradeCost">hacknetnodes[i].getRamUpgradeCost() (hacknetnodes[i] method)</a>
|
||||
</li>
|
||||
<li><a href="netscripthacknetnodeapi.html#hacknetnodes[i].level">hacknetnodes[i].level() (hacknetnodes[i] method)</a>
|
||||
</li>
|
||||
<li><a href="netscripthacknetnodeapi.html#hacknetnodes[i].moneyGainRatePerSecond">hacknetnodes[i].moneyGainRatePerSecond() (hacknetnodes[i] method)</a>
|
||||
<li><a href="netscripthacknetnodeapi.html#hacknetnodes[i].moneyGainRatePerSecond">hacknetnodes[i].moneyGainRatePerSecond (hacknetnodes[i] attribute)</a>
|
||||
</li>
|
||||
</ul></td>
|
||||
<td style="width: 33%; vertical-align: top;"><ul>
|
||||
<li><a href="netscripthacknetnodeapi.html#hacknetnodes[i].onlineTimeSeconds">hacknetnodes[i].onlineTimeSeconds() (hacknetnodes[i] method)</a>
|
||||
<li><a href="netscripthacknetnodeapi.html#hacknetnodes[i].onlineTimeSeconds">hacknetnodes[i].onlineTimeSeconds (hacknetnodes[i] attribute)</a>
|
||||
</li>
|
||||
<li><a href="netscripthacknetnodeapi.html#hacknetnodes[i].ram">hacknetnodes[i].ram() (hacknetnodes[i] method)</a>
|
||||
<li><a href="netscripthacknetnodeapi.html#hacknetnodes[i].ram">hacknetnodes[i].ram (hacknetnodes[i] attribute)</a>
|
||||
</li>
|
||||
<li><a href="netscripthacknetnodeapi.html#hacknetnodes[i].totalMoneyGenerated">hacknetnodes[i].totalMoneyGenerated() (hacknetnodes[i] method)</a>
|
||||
</li>
|
||||
<li><a href="netscripthacknetnodeapi.html#hacknetnodes[i].upgradeCore">hacknetnodes[i].upgradeCore() (hacknetnodes[i] method)</a>
|
||||
</li>
|
||||
<li>
|
||||
hacknetnodes[i].upgradeLevel(n)
|
||||
|
||||
<ul>
|
||||
<li><a href="netscripthacknetnodeapi.html#hacknetnodes[i].upgradeLevel(n);">() (hacknetnodes[i] method)</a>
|
||||
</li>
|
||||
</ul></li>
|
||||
<li><a href="netscripthacknetnodeapi.html#hacknetnodes[i].upgradeRam">hacknetnodes[i].upgradeRam() (hacknetnodes[i] method)</a>
|
||||
<li><a href="netscripthacknetnodeapi.html#hacknetnodes[i].totalMoneyGenerated">hacknetnodes[i].totalMoneyGenerated (hacknetnodes[i] attribute)</a>
|
||||
</li>
|
||||
<li><a href="netscriptfunctions.html#hasRootAccess">hasRootAccess() (built-in function)</a>
|
||||
</li>
|
||||
@@ -316,6 +294,10 @@
|
||||
|
||||
<h2 id="N">N</h2>
|
||||
<table style="width: 100%" class="indextable genindextable"><tr>
|
||||
<td style="width: 33%; vertical-align: top;"><ul>
|
||||
<li><a href="netscriptmisc.html#NetscriptPort.data">NetscriptPort.data (NetscriptPort attribute)</a>
|
||||
</li>
|
||||
</ul></td>
|
||||
<td style="width: 33%; vertical-align: top;"><ul>
|
||||
<li><a href="netscriptfunctions.html#nuke">nuke() (built-in function)</a>
|
||||
</li>
|
||||
|
||||
Vendored
+2
@@ -196,9 +196,11 @@ secrets that you've been searching for.</p>
|
||||
</ul>
|
||||
</li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="netscriptmisc.html"> Miscellaneous</a><ul>
|
||||
<li class="toctree-l3"><a class="reference internal" href="netscriptmisc.html#netscript-ports">Netscript Ports</a></li>
|
||||
<li class="toctree-l3"><a class="reference internal" href="netscriptmisc.html#comments">Comments</a></li>
|
||||
<li class="toctree-l3"><a class="reference internal" href="netscriptmisc.html#javascript-math-module">Javascript Math Module</a></li>
|
||||
<li class="toctree-l3"><a class="reference internal" href="netscriptmisc.html#javascript-date-module">Javascript Date Module</a></li>
|
||||
<li class="toctree-l3"><a class="reference internal" href="netscriptmisc.html#javascript-number-module">Javascript Number Module</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
Vendored
+2
@@ -197,9 +197,11 @@ to reach out to the developer!</p>
|
||||
</ul>
|
||||
</li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="netscriptmisc.html"> Miscellaneous</a><ul>
|
||||
<li class="toctree-l2"><a class="reference internal" href="netscriptmisc.html#netscript-ports">Netscript Ports</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="netscriptmisc.html#comments">Comments</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="netscriptmisc.html#javascript-math-module">Javascript Math Module</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="netscriptmisc.html#javascript-date-module">Javascript Date Module</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="netscriptmisc.html#javascript-number-module">Javascript Number Module</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
@@ -122,6 +122,7 @@ will only give 10% of the money you would have received in BitNode-1. The object
|
||||
<li class="toctree-l2"><a class="reference internal" href="netscripthacknetnodeapi.html"> Hacknet Node API</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="netscriptixapi.html"> Trade Information eXchange (TIX) API</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="netscriptsingularityfunctions.html"> Singularity Functions</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="netscriptmisc.html"> Miscellaneous</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
+1
@@ -112,6 +112,7 @@ can also change. For example, if a variable initially holds a number, it can lat
|
||||
<li class="toctree-l2"><a class="reference internal" href="netscripthacknetnodeapi.html"> Hacknet Node API</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="netscriptixapi.html"> Trade Information eXchange (TIX) API</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="netscriptsingularityfunctions.html"> Singularity Functions</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="netscriptmisc.html"> Miscellaneous</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
+23
-22
@@ -72,39 +72,39 @@ accessed using <em>hacknetnodes[0]</em>. The fourth Hacknet Node you purchase wi
|
||||
<p>The following is a list of member variables for a Hacknet Node object. These variables are read-only, which means you cannot assign
|
||||
a value to these.</p>
|
||||
<p>Note that these must be called on an element inside the <em>hacknetnodes</em> array, not the array itself.</p>
|
||||
<dl class="function">
|
||||
<dl class="attribute">
|
||||
<dt id="hacknetnodes[i].level">
|
||||
<code class="descclassname">hacknetnodes[i].</code><code class="descname">level</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#hacknetnodes[i].level" title="Permalink to this definition">¶</a></dt>
|
||||
<code class="descclassname">hacknetnodes[i].</code><code class="descname">level</code><a class="headerlink" href="#hacknetnodes[i].level" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Returns the level of the corresponding Hacknet Node</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dl class="attribute">
|
||||
<dt id="hacknetnodes[i].ram">
|
||||
<code class="descclassname">hacknetnodes[i].</code><code class="descname">ram</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#hacknetnodes[i].ram" title="Permalink to this definition">¶</a></dt>
|
||||
<code class="descclassname">hacknetnodes[i].</code><code class="descname">ram</code><a class="headerlink" href="#hacknetnodes[i].ram" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Returns the amount of RAM on the corresponding Hacknet Node</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dl class="attribute">
|
||||
<dt id="hacknetnodes[i].cores">
|
||||
<code class="descclassname">hacknetnodes[i].</code><code class="descname">cores</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#hacknetnodes[i].cores" title="Permalink to this definition">¶</a></dt>
|
||||
<code class="descclassname">hacknetnodes[i].</code><code class="descname">cores</code><a class="headerlink" href="#hacknetnodes[i].cores" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Returns the number of cores on the corresponding Hacknet Node</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dl class="attribute">
|
||||
<dt id="hacknetnodes[i].totalMoneyGenerated">
|
||||
<code class="descclassname">hacknetnodes[i].</code><code class="descname">totalMoneyGenerated</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#hacknetnodes[i].totalMoneyGenerated" title="Permalink to this definition">¶</a></dt>
|
||||
<code class="descclassname">hacknetnodes[i].</code><code class="descname">totalMoneyGenerated</code><a class="headerlink" href="#hacknetnodes[i].totalMoneyGenerated" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Returns the total amount of money that the corresponding Hacknet Node has earned</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dl class="attribute">
|
||||
<dt id="hacknetnodes[i].onlineTimeSeconds">
|
||||
<code class="descclassname">hacknetnodes[i].</code><code class="descname">onlineTimeSeconds</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#hacknetnodes[i].onlineTimeSeconds" title="Permalink to this definition">¶</a></dt>
|
||||
<code class="descclassname">hacknetnodes[i].</code><code class="descname">onlineTimeSeconds</code><a class="headerlink" href="#hacknetnodes[i].onlineTimeSeconds" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Returns the total amount of time (in seconds) that the corresponding Hacknet Node has existed</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dl class="attribute">
|
||||
<dt id="hacknetnodes[i].moneyGainRatePerSecond">
|
||||
<code class="descclassname">hacknetnodes[i].</code><code class="descname">moneyGainRatePerSecond</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#hacknetnodes[i].moneyGainRatePerSecond" title="Permalink to this definition">¶</a></dt>
|
||||
<code class="descclassname">hacknetnodes[i].</code><code class="descname">moneyGainRatePerSecond</code><a class="headerlink" href="#hacknetnodes[i].moneyGainRatePerSecond" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Returns the amount of income that the corresponding Hacknet Node earns</p>
|
||||
</dd></dl>
|
||||
|
||||
@@ -114,9 +114,9 @@ a value to these.</p>
|
||||
<p>The following is a list of supported functions/methods for a Hacknet Node object.</p>
|
||||
<p>Note that these must be called on an element inside the <em>hacknetnodes</em> array, not the
|
||||
array itself.</p>
|
||||
<dl class="function">
|
||||
<dt id="hacknetnodes[i].upgradeLevel(n);">
|
||||
<code class="descclassname">hacknetnodes[i].</code><code class="descname">upgradeLevel(n);</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#hacknetnodes[i].upgradeLevel(n);" title="Permalink to this definition">¶</a></dt>
|
||||
<dl class="method">
|
||||
<dt id="hacknetnodes[i].upgradeLevel">
|
||||
<code class="descclassname">hacknetnodes[i].</code><code class="descname">upgradeLevel</code><span class="sig-paren">(</span><em>n</em><span class="sig-paren">)</span><a class="headerlink" href="#hacknetnodes[i].upgradeLevel" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><table class="docutils field-list" frame="void" rules="none">
|
||||
<col class="field-name" />
|
||||
<col class="field-body" />
|
||||
@@ -133,23 +133,23 @@ Hacknet Node's level is successfully upgraded <em>n</em> times or up to the max
|
||||
otherwise.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dl class="method">
|
||||
<dt id="hacknetnodes[i].upgradeRam">
|
||||
<code class="descclassname">hacknetnodes[i].</code><code class="descname">upgradeRam</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#hacknetnodes[i].upgradeRam" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Tries to upgrade the amount of RAM on the corresponding Hacknet Node. Returns true if the RAM is
|
||||
successfully upgraded and false otherwise.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dl class="method">
|
||||
<dt id="hacknetnodes[i].upgradeCore">
|
||||
<code class="descclassname">hacknetnodes[i].</code><code class="descname">upgradeCore</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#hacknetnodes[i].upgradeCore" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Tries to purchase an additional core for the corresponding Hacknet Node. Returns true if the
|
||||
additional core is successfully purchased, and false otherwise.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dt id="hacknetnodes[i].getLevelUpgradeCost(n);">
|
||||
<code class="descclassname">hacknetnodes[i].</code><code class="descname">getLevelUpgradeCost(n);</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#hacknetnodes[i].getLevelUpgradeCost(n);" title="Permalink to this definition">¶</a></dt>
|
||||
<dl class="method">
|
||||
<dt id="hacknetnodes[i].getLevelUpgradeCost">
|
||||
<code class="descclassname">hacknetnodes[i].</code><code class="descname">getLevelUpgradeCost</code><span class="sig-paren">(</span><em>n</em><span class="sig-paren">)</span><a class="headerlink" href="#hacknetnodes[i].getLevelUpgradeCost" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><table class="docutils field-list" frame="void" rules="none">
|
||||
<col class="field-name" />
|
||||
<col class="field-body" />
|
||||
@@ -164,13 +164,13 @@ additional core is successfully purchased, and false otherwise.</p>
|
||||
<p>Returns the cost of upgrading the specified Hacknet Node by <em>n</em> levels</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dl class="method">
|
||||
<dt id="hacknetnodes[i].getRamUpgradeCost">
|
||||
<code class="descclassname">hacknetnodes[i].</code><code class="descname">getRamUpgradeCost</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#hacknetnodes[i].getRamUpgradeCost" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Returns the cost of upgrading the RAM of the specified Hacknet Node. Upgrading a Node's RAM doubles it.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="function">
|
||||
<dl class="method">
|
||||
<dt id="hacknetnodes[i].getCoreUpgradeCost">
|
||||
<code class="descclassname">hacknetnodes[i].</code><code class="descname">getCoreUpgradeCost</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#hacknetnodes[i].getCoreUpgradeCost" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Returns the cost of upgrading the number of cores of the specified Hacknet Node. Upgrading a Node's
|
||||
@@ -241,6 +241,7 @@ Nodes to a level of at least 75, RAM to at least 8GB, and number of cores to at
|
||||
</li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="netscriptixapi.html"> Trade Information eXchange (TIX) API</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="netscriptsingularityfunctions.html"> Singularity Functions</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="netscriptmisc.html"> Miscellaneous</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
Vendored
+1
@@ -326,6 +326,7 @@ NOT case-sensitive.</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="netscriptsingularityfunctions.html"> Singularity Functions</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="netscriptmisc.html"> Miscellaneous</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
Vendored
+167
@@ -50,6 +50,162 @@
|
||||
|
||||
<div class="section" id="netscript-miscellaneous">
|
||||
<h1>Netscript Miscellaneous<a class="headerlink" href="#netscript-miscellaneous" title="Permalink to this headline">¶</a></h1>
|
||||
<div class="section" id="netscript-ports">
|
||||
<h2>Netscript Ports<a class="headerlink" href="#netscript-ports" title="Permalink to this headline">¶</a></h2>
|
||||
<p>Netscript ports are endpoints that can be used to communicate between scripts.
|
||||
A port is implemented as a sort of serialized queue, where you can only write
|
||||
and read one element at a time from the port. When you read data from a port,
|
||||
the element that is read is removed from the port.</p>
|
||||
<p>The <code class="xref js js-func docutils literal"><span class="pre">read()</span></code>, <code class="xref js js-func docutils literal"><span class="pre">write()</span></code>, <code class="xref js js-func docutils literal"><span class="pre">clear()</span></code>, and <code class="xref js js-func docutils literal"><span class="pre">peek()</span></code>
|
||||
Netscript functions can be used to interact with ports.</p>
|
||||
<p>Right now, there are only 20 ports for Netscript, denoted by the number 1
|
||||
through 20. When using the functions above, the ports are specified
|
||||
by passing the number as the first argument.</p>
|
||||
<p>IMPORTANT: The data inside ports are not saved! This means if you close and
|
||||
re-open the game, or reload the page then you will lose all of the data in
|
||||
the ports!</p>
|
||||
<p><strong>Example Usage</strong></p>
|
||||
<p>Here's a brief example of how ports work. For the sake of simplicity we'll only deal with port 1.</p>
|
||||
<p>Let's assume Port 1 starts out empty (no data inside). We'll represent the port as such:</p>
|
||||
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="p">[]</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>Now assume we ran the following simple script:</p>
|
||||
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="k">for</span> <span class="p">(</span><span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="mi">10</span><span class="p">;</span> <span class="o">++</span><span class="n">i</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="n">write</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="n">i</span><span class="p">);</span> <span class="o">//</span><span class="n">Writes</span> <span class="n">the</span> <span class="n">value</span> <span class="n">of</span> <span class="n">i</span> <span class="n">to</span> <span class="n">port</span> <span class="mi">1</span>
|
||||
<span class="p">}</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>After this script executes, our script will contain every number from 0 through 9, as so:</p>
|
||||
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">6</span><span class="p">,</span> <span class="mi">7</span> <span class="p">,</span> <span class="mi">8</span><span class="p">,</span> <span class="mi">9</span><span class="p">]</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>Then, assume we run the following script:</p>
|
||||
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="k">for</span> <span class="p">(</span><span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="mi">3</span><span class="p">;</span> <span class="o">++</span><span class="n">i</span><span class="p">)</span> <span class="p">{</span>
|
||||
<span class="nb">print</span><span class="p">(</span><span class="n">read</span><span class="p">(</span><span class="mi">1</span><span class="p">));</span> <span class="o">//</span><span class="n">Reads</span> <span class="n">a</span> <span class="n">value</span> <span class="kn">from</span> <span class="nn">port</span> <span class="mi">1</span> <span class="ow">and</span> <span class="n">then</span> <span class="n">prints</span> <span class="n">it</span>
|
||||
<span class="p">}</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>This script above will read the first three values from port 1 and then print them to the script's log. The log will end up looking like:</p>
|
||||
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="mi">0</span>
|
||||
<span class="mi">1</span>
|
||||
<span class="mi">2</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>And the data in port 1 will look like:</p>
|
||||
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="p">[</span><span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">6</span><span class="p">,</span> <span class="mi">7</span><span class="p">,</span> <span class="mi">8</span><span class="p">,</span> <span class="mi">9</span><span class="p">]</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p><strong>Port Handles</strong></p>
|
||||
<p>The <code class="xref js js-func docutils literal"><span class="pre">getPortHandle()</span></code> Netscript function can be used to get a handle to a Netscript Port.
|
||||
This handle allows you to access several new port-related functions and the
|
||||
port's underlying data structure, which is just a Javascript array. The functions are:</p>
|
||||
<dl class="method">
|
||||
<dt id="NetscriptPort.write">
|
||||
<code class="descclassname">NetscriptPort.</code><code class="descname">write</code><span class="sig-paren">(</span><em>data</em><span class="sig-paren">)</span><a class="headerlink" href="#NetscriptPort.write" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><table class="docutils field-list" frame="void" rules="none">
|
||||
<col class="field-name" />
|
||||
<col class="field-body" />
|
||||
<tbody valign="top">
|
||||
<tr class="field-odd field"><th class="field-name">Arguments:</th><td class="field-body"><ul class="first simple">
|
||||
<li><strong>data</strong> -- Data to write to the port</li>
|
||||
</ul>
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">If the port is full, the item that is removed from the port is returned.
|
||||
Otherwise, null is returned.</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<p>Writes <cite>data</cite> to the port. Works the same as the Netscript function <cite>write</cite>.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="method">
|
||||
<dt id="NetscriptPort.tryWrite">
|
||||
<code class="descclassname">NetscriptPort.</code><code class="descname">tryWrite</code><span class="sig-paren">(</span><em>data</em><span class="sig-paren">)</span><a class="headerlink" href="#NetscriptPort.tryWrite" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><table class="docutils field-list" frame="void" rules="none">
|
||||
<col class="field-name" />
|
||||
<col class="field-body" />
|
||||
<tbody valign="top">
|
||||
<tr class="field-odd field"><th class="field-name">Arguments:</th><td class="field-body"><ul class="first simple">
|
||||
<li><strong>data</strong> -- Data to try to write to the port</li>
|
||||
</ul>
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">True if the data is successfully written to the port, and false otherwise.</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<p>Attempts to write <cite>data</cite> to the Netscript port. If the port is full, the data will
|
||||
not be written. Otherwise, the data will be written normally.</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="method">
|
||||
<dt id="NetscriptPort.full">
|
||||
<code class="descclassname">NetscriptPort.</code><code class="descname">full</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#NetscriptPort.full" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><table class="docutils field-list" frame="void" rules="none">
|
||||
<col class="field-name" />
|
||||
<col class="field-body" />
|
||||
<tbody valign="top">
|
||||
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">True if the Netscript Port is full, and false otherwise</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="method">
|
||||
<dt id="NetscriptPort.empty">
|
||||
<code class="descclassname">NetscriptPort.</code><code class="descname">empty</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#NetscriptPort.empty" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><table class="docutils field-list" frame="void" rules="none">
|
||||
<col class="field-name" />
|
||||
<col class="field-body" />
|
||||
<tbody valign="top">
|
||||
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">True if the Netscript Port is empty, and false otherwise</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="method">
|
||||
<dt id="NetscriptPort.clear">
|
||||
<code class="descclassname">NetscriptPort.</code><code class="descname">clear</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#NetscriptPort.clear" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Clears all data from the port. Works the same as the Netscript function <cite>clear</cite></p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="attribute">
|
||||
<dt id="NetscriptPort.data">
|
||||
<code class="descclassname">NetscriptPort.</code><code class="descname">data</code><a class="headerlink" href="#NetscriptPort.data" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>The Netscript port underlying data structure, which is just a Javascript array. All
|
||||
valid Javascript Array methods can be called on this.</p>
|
||||
</dd></dl>
|
||||
|
||||
<p>Port Handle Example:</p>
|
||||
<div class="highlight-default"><div class="highlight"><pre><span></span>port = getPortHandle(5);
|
||||
back = port.data.pop(); //Get and remove last element in port
|
||||
|
||||
//Remove an element from the port
|
||||
i = port.data.findIndex("foo");
|
||||
if (i != -1) {
|
||||
port.data.slice(i, 1);
|
||||
}
|
||||
|
||||
//Wait for port data before reading
|
||||
while(port.empty()) {
|
||||
sleep(10000);
|
||||
}
|
||||
res = port.read();
|
||||
|
||||
//Wait for there to be room in a port before writing
|
||||
while (!port.tryWrite(5)) {
|
||||
sleep(5000);
|
||||
}
|
||||
|
||||
//Successfully wrote to port!
|
||||
</pre></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="comments">
|
||||
<h2>Comments<a class="headerlink" href="#comments" title="Permalink to this headline">¶</a></h2>
|
||||
<p>Netscript supports comments using the same syntax as <a class="reference external" href="https://www.w3schools.com/js/js_comments.asp">Javascript comments</a>.
|
||||
@@ -85,6 +241,15 @@ However, since the 'new' operator does not work in Netscript, only the Date modu
|
||||
</pre></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="javascript-number-module">
|
||||
<h2>Javascript Number Module<a class="headerlink" href="#javascript-number-module" title="Permalink to this headline">¶</a></h2>
|
||||
<p>The <a class="reference external" href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">Javascript Number module</a> is supported in Netscript.</p>
|
||||
<p>Example:</p>
|
||||
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">tprint</span><span class="p">(</span><span class="n">Number</span><span class="o">.</span><span class="n">isInteger</span><span class="p">(</span><span class="mi">1</span><span class="p">));</span> <span class="o">//</span><span class="kc">True</span>
|
||||
<span class="n">tprint</span><span class="p">(</span><span class="n">Number</span><span class="o">.</span><span class="n">isInteger</span><span class="p">(</span><span class="mf">1.534059</span><span class="p">));</span> <span class="o">//</span><span class="kc">False</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -107,9 +272,11 @@ However, since the 'new' operator does not work in Netscript, only the Date modu
|
||||
<li class="toctree-l2"><a class="reference internal" href="netscriptixapi.html"> Trade Information eXchange (TIX) API</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="netscriptsingularityfunctions.html"> Singularity Functions</a></li>
|
||||
<li class="toctree-l2 current"><a class="current reference internal" href="#"> Miscellaneous</a><ul>
|
||||
<li class="toctree-l3"><a class="reference internal" href="#netscript-ports">Netscript Ports</a></li>
|
||||
<li class="toctree-l3"><a class="reference internal" href="#comments">Comments</a></li>
|
||||
<li class="toctree-l3"><a class="reference internal" href="#javascript-math-module">Javascript Math Module</a></li>
|
||||
<li class="toctree-l3"><a class="reference internal" href="#javascript-date-module">Javascript Date Module</a></li>
|
||||
<li class="toctree-l3"><a class="reference internal" href="#javascript-number-module">Javascript Number Module</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
+1
@@ -209,6 +209,7 @@ change the value of their operands. For example:</p>
|
||||
<li class="toctree-l2"><a class="reference internal" href="netscripthacknetnodeapi.html"> Hacknet Node API</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="netscriptixapi.html"> Trade Information eXchange (TIX) API</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="netscriptsingularityfunctions.html"> Singularity Functions</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="netscriptmisc.html"> Miscellaneous</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
@@ -87,6 +87,7 @@ script specified in the first argument with the amount of threads specified in t
|
||||
<li class="toctree-l2"><a class="reference internal" href="netscripthacknetnodeapi.html"> Hacknet Node API</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="netscriptixapi.html"> Trade Information eXchange (TIX) API</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="netscriptsingularityfunctions.html"> Singularity Functions</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="netscriptmisc.html"> Miscellaneous</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
Vendored
BIN
Binary file not shown.
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user