Netscript Hacknet Node API

Netscript provides the following API for accessing and upgrading your Hacknet Nodes through scripts. This API does NOT work offline.

'''None of the functions from this API will write to the script's logs. If you want to see what your script is doing you will have to use the print Netscript function.'''

hacknetnodes
A special variable. This is an array that maps to the Player's Hacknet Nodes. The Hacknet Nodes are accessed through indexes. 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 same 'hacknet-node-0' and can be accessed with hacknetnodes[0]. The fourth Hacknet Node you purchase will have the name 'hacknet-node-3' and can be accessed with hacknetnodes[3].

hacknetnodes.length
A member variable for the  array that returns the number of Hacknet Nodes that the player owns.

Hacknet Node Member Variables
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.

Note that these must be called on an element inside the  array, not the array itself.

hacknetnodes[i].level
Returns the level of the corresponding Hacknet Node

hacknetnodes[i].ram
Returns the amount of RAM on the corresponding Hacknet Node

hacknetnodes[i].cores
Returns the number of cores on the corresponding Hacknet Node

hacknetnodes[i].totalMoneyGenerated
Returns the total amount of money that the corresponding Hacknet Node has earned

hacknetnodes[i].onlineTimeSeconds
Returns the total amount of time (in seconds) that the corresponding Hacknet Node has existed

hacknetnodes[i].moneyGainRatePerSecond
Returns the amount of income that the corresponding Hacknet Node earns

Hacknet Node Methods
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  array, not the array itself.

hacknetnodes[i].upgradeLevel(n)
Tries to upgrade the level of the corresponding Hacknet Node n times. The argument n must be a positive integer. Returns true if the Hacknet Node's level is successfully upgraded n times or up to the max level (200), and false otherwise.

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.

hacknetnodes[i].upgradeCore
Attempts to purchase an additional core for the corresponding Hacknet Node. Returns true if the additional core is successfully purchase, and false otherwise.

hacknetnodes[i].getLevelUpgradeCost(n)
Returns the cost of upgrading the specified Hacknet Node by n levels.

hacknetnodes[i].getRamUpgradeCost
Returns the cost of upgrading the RAM of the specified Hacknet Node. Upgrading a Node's RAM doubles it.

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 an additional core.

Example(s)
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.