bitburner-src/doc/build/html/netscripthacknetnodeapi.html

349 lines
23 KiB
HTML
Raw Normal View History

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="English">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Netscript Hacknet Node API &#8212; Bitburner 1.0 documentation</title>
<link rel="stylesheet" href="_static/agogo.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: './',
VERSION: '1.0',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true,
SOURCELINK_SUFFIX: '.txt'
};
</script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="Netscript Trade Information eXchange (TIX) API" href="netscriptixapi.html" />
<link rel="prev" title="Netscript Advanced Functions" href="netscriptadvancedfunctions.html" />
</head>
<body>
<div class="header-wrapper" role="banner">
<div class="header">
<div class="headertitle"><a
href="index.html">Bitburner 1.0 documentation</a></div>
<div class="rel" role="navigation" aria-label="related navigation">
<a href="netscriptadvancedfunctions.html" title="Netscript Advanced Functions"
accesskey="P">previous</a> |
<a href="netscriptixapi.html" title="Netscript Trade Information eXchange (TIX) API"
accesskey="N">next</a> |
<a href="genindex.html" title="General Index"
accesskey="I">index</a>
</div>
</div>
</div>
<div class="content-wrapper">
<div class="content">
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<div class="section" id="netscript-hacknet-node-api">
<h1>Netscript Hacknet Node API<a class="headerlink" href="#netscript-hacknet-node-api" title="Permalink to this headline"></a></h1>
<p>Netscript provides the following API for accessing and upgrading your Hacknet Nodes
through scripts.</p>
<p>Note that none of these functions will write to the script's logs. If you want
to see what your script is doing you will have to print to the logs yourself.</p>
<div class="section" id="hacknetnodes">
<h2>hacknetnodes<a class="headerlink" href="#hacknetnodes" title="Permalink to this headline"></a></h2>
<blockquote>
<div><em>hacknetnodes</em> is a special variable. It is an array that maps to the player's
Hacknet Nodes. The Hacknet Nodes are accessed through indexed. These indexes
correspond to the number at the end of the name of the Hacknet Node. For example,
the first Hacknet Node you purchase will have the name &quot;hacknet-node-0&quot; and can be
accessed using <em>hacknetnodes[0]</em>. The fourth Hacknet Node you purchase will have the name
&quot;hacknet-node-3&quot; and can be accessed using <em>hacknetnodes[3]</em>.</div></blockquote>
</div>
<div class="section" id="purchasing-hacknet-nodes">
<h2>Purchasing Hacknet Nodes<a class="headerlink" href="#purchasing-hacknet-nodes" title="Permalink to this headline"></a></h2>
<p>The following is a list of supported functions for purchasing Hacknet Nodes.</p>
<dl class="function">
<dt id="getNextHacknetNodeCost">
<code class="descname">getNextHacknetNodeCost</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#getNextHacknetNodeCost" title="Permalink to this definition"></a></dt>
<dd><p>Returns the cost of purchasing a new Hacknet Node</p>
</dd></dl>
<dl class="function">
<dt id="purchaseHacknetNode">
<code class="descname">purchaseHacknetNode</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#purchaseHacknetNode" title="Permalink to this definition"></a></dt>
<dd><p>Purchases a new Hacknet Node. Returns a number with the index of the Hacknet Node. This index is equivalent to the number at the
end of the Hacknet Node's name (e.g The Hacknet Node named 'hacknet-node-4' will have an index of 4). If the player cannot afford
to purchase a new Hacknet Node then the function will return false.</p>
</dd></dl>
</div>
<div class="section" id="hacknet-node-member-variables">
<h2>Hacknet Node Member Variables<a class="headerlink" href="#hacknet-node-member-variables" title="Permalink to this headline"></a></h2>
<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="attribute">
<dt id="hacknetnodes[i].name">
<code class="descclassname">hacknetnodes[i].</code><code class="descname">name</code><a class="headerlink" href="#hacknetnodes[i].name" title="Permalink to this definition"></a></dt>
<dd><p>Returns the name of the corresponding Hacknet Node</p>
</dd></dl>
<dl class="attribute">
<dt id="hacknetnodes[i].level">
<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="attribute">
<dt id="hacknetnodes[i].ram">
<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="attribute">
<dt id="hacknetnodes[i].cores">
<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="attribute">
<dt id="hacknetnodes[i].totalMoneyGenerated">
<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="attribute">
<dt id="hacknetnodes[i].onlineTimeSeconds">
<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="attribute">
<dt id="hacknetnodes[i].moneyGainRatePerSecond">
<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>
</div>
<div class="section" id="hacknet-node-methods">
<h2>Hacknet Node Methods<a class="headerlink" href="#hacknet-node-methods" title="Permalink to this headline"></a></h2>
<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="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" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Arguments:</th><td class="field-body"><ul class="first last simple">
<li><strong>n</strong> (<em>number</em>) -- Number of levels to upgrade. Must be positive. Rounded to nearest integer</li>
</ul>
</td>
</tr>
</tbody>
</table>
<p>Tries to upgrade the level of the corresponding Hacknet Node <em>n</em> times. Returns true if the
Hacknet Node's level is successfully upgraded <em>n</em> times or up to the max level (200), and false
otherwise.</p>
</dd></dl>
<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="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="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" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Arguments:</th><td class="field-body"><ul class="first last simple">
<li><strong>n</strong> (<em>number</em>) -- Number of levels to upgrade. Must be positive. Rounded to nearest integer</li>
</ul>
</td>
</tr>
</tbody>
</table>
<p>Returns the cost of upgrading the specified Hacknet Node by <em>n</em> levels</p>
</dd></dl>
<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="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
number of cores adds one additional core.</p>
</dd></dl>
</div>
<div class="section" id="utils">
<h2>Utils<a class="headerlink" href="#utils" title="Permalink to this headline"></a></h2>
<dl class="function">
<dt id="getHacknetMultipliers">
<code class="descname">getHacknetMultipliers</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#getHacknetMultipliers" title="Permalink to this definition"></a></dt>
<dd><p>Returns an object containing the Player's hacknet related multipliers. These multipliers are
returned in integer forms, not percentages (e.g. 1.5 instead of 150%). The object has the following structure:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="p">{</span>
<span class="n">production</span><span class="p">:</span> <span class="n">Player</span><span class="s1">&#39;s hacknet production multiplier,</span>
<span class="n">purchaseCost</span><span class="p">:</span> <span class="n">Player</span><span class="s1">&#39;s hacknet purchase cost multiplier,</span>
<span class="n">ramCost</span><span class="p">:</span> <span class="n">Player</span><span class="s1">&#39;s hacknet ram cost multiplier,</span>
<span class="n">coreCost</span><span class="p">:</span> <span class="n">Player</span><span class="s1">&#39;s hacknet core cost multiplier,</span>
<span class="n">levelCost</span><span class="p">:</span> <span class="n">Player</span><span class="s1">&#39;s hacknet level cost multiplier</span>
<span class="p">}</span>
</pre></div>
</div>
<p>Example of how this can be used:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">mults</span> <span class="o">=</span> <span class="n">getHacknetMultipliers</span><span class="p">();</span>
<span class="nb">print</span><span class="p">(</span><span class="n">mults</span><span class="o">.</span><span class="n">production</span><span class="p">);</span>
<span class="nb">print</span><span class="p">(</span><span class="n">mults</span><span class="o">.</span><span class="n">purchaseCost</span><span class="p">);</span>
</pre></div>
</div>
</dd></dl>
</div>
<div class="section" id="example-s">
<h2>Example(s)<a class="headerlink" href="#example-s" title="Permalink to this headline"></a></h2>
<p>The following is an example of one way a script can be used to automate the purchasing and upgrading of Hacknet Nodes.
This script purchases new Hacknet Nodes until the player has four. Then, it iteratively upgrades each of those four Hacknet
Nodes to a level of at least 75, RAM to at least 8GB, and number of cores to at least 2:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="o">//</span><span class="n">Purchase</span> <span class="mi">4</span> <span class="n">Hacknet</span> <span class="n">Nodes</span>
<span class="k">while</span><span class="p">(</span><span class="n">hacknetnodes</span><span class="o">.</span><span class="n">length</span> <span class="o">&lt;</span> <span class="mi">4</span><span class="p">)</span> <span class="p">{</span>
<span class="n">purchaseHacknetNode</span><span class="p">();</span>
<span class="p">}</span>
<span class="o">//</span><span class="n">Upgrade</span> <span class="nb">all</span> <span class="mi">4</span> <span class="n">Hacknet</span> <span class="n">Nodes</span> <span class="n">to</span> <span class="n">at</span> <span class="n">least</span> <span class="n">level</span> <span class="mi">75</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">&lt;</span> <span class="mi">4</span><span class="p">;</span> <span class="n">i</span> <span class="o">=</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span>
<span class="k">while</span> <span class="p">(</span><span class="n">hacknetnodes</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">level</span> <span class="o">&lt;=</span> <span class="mi">75</span><span class="p">)</span> <span class="p">{</span>
<span class="n">hacknetnodes</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">upgradeLevel</span><span class="p">(</span><span class="mi">5</span><span class="p">);</span>
<span class="n">sleep</span><span class="p">(</span><span class="mi">10000</span><span class="p">);</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="o">//</span><span class="n">Upgrade</span> <span class="n">RAM</span> <span class="n">on</span> <span class="nb">all</span> <span class="n">Hacknet</span> <span class="n">Nodes</span> <span class="n">to</span> <span class="mi">8</span><span class="n">GB</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">&lt;</span> <span class="mi">4</span><span class="p">;</span> <span class="n">i</span> <span class="o">=</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span>
<span class="k">while</span> <span class="p">(</span><span class="n">hacknetnodes</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">ram</span> <span class="o">&lt;</span> <span class="mi">8</span><span class="p">)</span> <span class="p">{</span>
<span class="n">hacknetnodes</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">upgradeRam</span><span class="p">();</span>
<span class="n">sleep</span><span class="p">(</span><span class="mi">10000</span><span class="p">);</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="o">//</span><span class="n">Upgrade</span> <span class="n">cores</span> <span class="n">on</span> <span class="nb">all</span> <span class="n">Hacknet</span> <span class="n">Nodes</span> <span class="n">to</span> <span class="mi">2</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">&lt;</span> <span class="mi">4</span><span class="p">;</span> <span class="n">i</span> <span class="o">=</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span>
<span class="k">while</span> <span class="p">(</span><span class="n">hacknetnodes</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">cores</span> <span class="o">&lt;</span> <span class="mi">2</span><span class="p">)</span> <span class="p">{</span>
<span class="n">hacknetnodes</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">upgradeCore</span><span class="p">();</span>
<span class="n">sleep</span><span class="p">(</span><span class="mi">10000</span><span class="p">);</span>
<span class="p">}</span>
<span class="p">}</span>
</pre></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="sidebar">
<h3>Table Of Contents</h3>
<p class="caption"><span class="caption-text">Contents:</span></p>
<ul class="current">
<li class="toctree-l1 current"><a class="reference internal" href="netscript.html"> Netscript</a><ul class="current">
2018-07-04 04:12:46 +02:00
<li class="toctree-l2"><a class="reference internal" href="netscriptjs.html"> NetscriptJS (Netscript 2.0)</a></li>
<li class="toctree-l2"><a class="reference internal" href="netscriptdatatypes.html"> Data Types and Variables</a></li>
<li class="toctree-l2"><a class="reference internal" href="netscriptoperators.html"> Operators</a></li>
<li class="toctree-l2"><a class="reference internal" href="netscriptloopsandconditionals.html"> Loops and Conditionals</a></li>
<li class="toctree-l2"><a class="reference internal" href="netscriptscriptarguments.html"> Script Arguments</a></li>
<li class="toctree-l2"><a class="reference internal" href="netscriptfunctions.html"> Basic Functions</a></li>
<li class="toctree-l2"><a class="reference internal" href="netscriptadvancedfunctions.html"> Advanced Functions</a></li>
<li class="toctree-l2 current"><a class="current reference internal" href="#"> Hacknet Node API</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#hacknetnodes">hacknetnodes</a></li>
<li class="toctree-l3"><a class="reference internal" href="#purchasing-hacknet-nodes">Purchasing Hacknet Nodes</a></li>
<li class="toctree-l3"><a class="reference internal" href="#hacknet-node-member-variables">Hacknet Node Member Variables</a></li>
<li class="toctree-l3"><a class="reference internal" href="#hacknet-node-methods">Hacknet Node Methods</a></li>
<li class="toctree-l3"><a class="reference internal" href="#utils">Utils</a></li>
<li class="toctree-l3"><a class="reference internal" href="#example-s">Example(s)</a></li>
</ul>
</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>
2018-07-04 04:12:46 +02:00
<li class="toctree-l2"><a class="reference internal" href="netscriptbladeburnerapi.html"> Bladeburner API</a></li>
<li class="toctree-l2"><a class="reference internal" href="netscriptmisc.html"> Miscellaneous</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="terminal.html"> Terminal</a></li>
2018-05-02 19:38:11 +02:00
<li class="toctree-l1"><a class="reference internal" href="shortcuts.html"> Keyboard Shortcuts</a></li>
2018-07-04 04:12:46 +02:00
<li class="toctree-l1"><a class="reference internal" href="changelog.html"> Changelog</a></li>
</ul>
<div role="search">
<h3 style="margin-top: 1.5em;">Search</h3>
<form class="search" action="search.html" method="get">
<input type="text" name="q" />
<input type="submit" value="Go" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="clearer"></div>
</div>
</div>
<div class="footer-wrapper">
<div class="footer">
<div class="left">
<div role="navigation" aria-label="related navigaton">
<a href="netscriptadvancedfunctions.html" title="Netscript Advanced Functions"
>previous</a> |
<a href="netscriptixapi.html" title="Netscript Trade Information eXchange (TIX) API"
>next</a> |
<a href="genindex.html" title="General Index"
>index</a>
</div>
<div role="note" aria-label="source link">
<br/>
<a href="_sources/netscripthacknetnodeapi.rst.txt"
rel="nofollow">Show Source</a>
</div>
</div>
<div class="right">
<div class="footer" role="contentinfo">
&#169; Copyright 2017, Bitburner.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.6.4.
</div>
</div>
<div class="clearer"></div>
</div>
</div>
</body>
</html>