This commit is contained in:
Olivier Gagnon
2021-11-17 19:56:17 -05:00
parent 6cf0455215
commit c69eb34341
237 changed files with 132 additions and 4979 deletions

View File

@@ -1,15 +0,0 @@
alert() Netscript Function
============================
.. js:function:: alert(message)
:RAM cost: 0 GB
:param string message: message to display
Spawns an alert box.
Example:
.. code-block:: javascript
alert("Reached $1b");

View File

@@ -1,16 +0,0 @@
clear() Netscript Function
==========================
.. js:function:: clear(portOrFilename)
:RAM cost: 1 GB
:param string/number portOrFilename: Port or text file to clear.
This function is used to clear data in a :ref:`Netscript Port <netscript_ports>` or a text file.
If the ``portOrFilename`` argument is a number between 1 and 20, then it
specifies a port and will clear it (deleting all data from the underlying queue).
If the ``portOrFilename`` argument is a string, then it specifies the name
of a text file (.txt) and will delete all data from that text file.

View File

@@ -1,17 +0,0 @@
clearLog() Netscript Function
=============================
.. js:function:: clearLog()
:RAM cost: 0 GB
Clears the script's logs. Useful when making monitoring scripts.
Examples:
.. code-block:: javascript
while(true) {
clearLog();
print(getServerMoneyAvailable('foodnstuff'));
}

View File

@@ -1,17 +0,0 @@
exit() Netscript Function
=========================
.. js:function:: exit()
:RAM cost: 0 GB
Terminates the current script immediately.
.. warning:: In :ref:`netscriptjs`, execution may continue past a call to
this function; while some game-related functions (e.g. those with an
``ns.`` prefix) will not function after this function has been called,
there might still be unintended behavior if you assume ``exit`` will
immediately halt execution, like it does in :ref:`netscript1`. To be
safe, you should probably ``return`` from the main function instead
of/in addition to calling ``ns.exit()`` when halting a NetscriptJS
script.

View File

@@ -1,46 +0,0 @@
flags() Netscript Function
============================
.. js:function:: flags(data)
:RAM cost: 0 GB
:param data array of pairs of strings: Flags definition.
:returns: Object containing all the flags that were parsed or default.
This function allows for a more flexible way of parsing script arguments
than to just pass a fixed list in a fixed order. Options can be given
names, and passed in any order, while having defined default values.
The flag definition is an array of pairs of values: the first value is the
name of the flag, and the 2nd value is the default value for that flag.
The return object is a map containing flag names to the value. It also
contains the special field '_', which contains all arguments that were not
flags.
Example:
.. code-block:: javascript
// example.script
var data = flags([
['delay', 0], // a default number means this flag is a number
['server', 'foodnstuff'], // a default string means this flag is a string
['exclude', []], // a default array means this flag is a default array of string
['help', false], // a default boolean means this flag is a boolean
]);
tprint(data);
/*
[home ~/]> run example.script
{"_":[],"delay":0,"server":"foodnstuff","exclude":[],"help":false}
[home ~/]> run example.script --delay 3000
{"_":[],"server":"foodnstuff","exclude":[],"help":false,"delay":3000}
[home ~/]> run example.script --delay 3000 --server harakiri-sushi
{"_":[],"exclude":[],"help":false,"delay":3000,"server":"harakiri-sushi"}
[home ~/]> run example.script --delay 3000 --server harakiri-sushi hello world
{"_":["hello","world"],"exclude":[],"help":false,"delay":3000,"server":"harakiri-sushi"}
[home ~/]> run example.script --delay 3000 --server harakiri-sushi hello world --exclude a --exclude b
{"_":["hello","world"],"help":false,"delay":3000,"server":"harakiri-sushi","exclude":["a","b"]}
[home ~/]> run example.script --help
{"_":[],"delay":0,"server":"foodnstuff","exclude":[],"help":true}
*/

View File

@@ -1,13 +0,0 @@
getFavorToDonate() Netscript Function
=====================================
.. js:function:: getFavorToDonate()
:RAM cost: 0.1 GB
:returns: Amount of faction favor required to unlock donation.
Example:
.. code-block:: javascript
getFavorToDonate() // returns: 150

View File

@@ -1,21 +0,0 @@
getGrowTime() Netscript Function
================================
.. js:function:: getGrowTime(hostname[, hackLvl=current level])
:RAM cost: 0.05 GB
:param string hostname: Hostname of target server.
:returns: seconds it takes to execute :doc:`grow<grow>` on that server.
The function takes in an optional ``hackLvl`` parameter that can be
specified to see what the grow time would be at different hacking levels.
Example:
.. code-block:: javascript
getGrowTime("foodnstuff"); // returns: 53.4
.. note:: For Hacknet Servers (the upgraded version of a Hacknet Node), this function will
return ``Infinity``.

View File

@@ -1,20 +0,0 @@
getHackTime() Netscript Function
================================
.. js:function:: getHackTime(hostname[, hackLvl=current level])
:RAM cost: 0.05 GB
:param string hostname: Hostname of target server.
:returns: seconds it takes to execute :doc:`hack<hack>` on that server.
The function takes in an optional ``hackLvl`` parameter that can be
specified to see what the hack time would be at different hacking levels.
Example:
.. code-block:: javascript
getHackTime("foodnstuff"); // returns: 53.4
.. note:: For Hacknet Servers (the upgraded version of a Hacknet Node), this function will
return :code:`Infinity`.

View File

@@ -1,13 +0,0 @@
getHostname() Netscript Function
================================
.. js:function:: getHostname()
:RAM cost: 0.05 GB
:returns: Hostname of the server this script is running on.
Example:
.. code-block:: javascript
getHostname(); // returns: "foodnstuff"

View File

@@ -1,101 +0,0 @@
getPlayer() Netscript Function
==============================
.. js:function:: getPlayer()
:RAM cost: 0.5 GB
The result of this function can be passed to the :doc:`formulas API<../netscriptformulasapi>`.
Returns an object with the Player's stats. The object has the following properties::
{
hacking: Current Hacking skill level
hp: Current health points
max_hp: Maximum health points
strength: Current Strength skill level
defense: Current Defense skill level
dexterity: Current Dexterity skill level
agility: Current Agility skill level
charisma: Current Charisma skill level
intelligence: Current Intelligence skill level (from BitNode-5)
hacking_chance_mult: Hacking Chance multiplier (from Source-Files and Augments)
hacking_speed_mult: Hacking Speed multiplier (from Source-Files and Augments)
hacking_money_mult: Hacking Money multiplier (from Source-Files and Augments)
hacking_grow_mult: Hacking Growth multiplier (from Source-Files and Augments)
hacking_exp: Current Hacking experience points
strength_exp: Current Strength experience points
defense_exp: Current Defense experience points
dexterity_exp: Current Dexterity experience points
agility_exp: Current Agility experience points
charisma_exp: Current Charisma experience points
hacking_mult: Hacking Level multiplier (from Source-Files and Augments)
strength_mult: Strength Level multiplier (from Source-Files and Augments)
defense_mult: Defense Level multiplier (from Source-Files and Augments)
dexterity_mult: Dexterity Level multiplier (from Source-Files and Augments)
agility_mult: Agility Level multiplier (from Source-Files and Augments)
charisma_mult: Charisma Level multiplier (from Source-Files and Augments)
hacking_exp_mult: Hacking Experience multiplier (from Source-Files and Augments)
strength_exp_mult: Strength Experience multiplier (from Source-Files and Augments)
defense_exp_mult: Defense Experience multiplier (from Source-Files and Augments)
dexterity_exp_mult: Dexterity Experience multiplier (from Source-Files and Augments)
agility_exp_mult: Agility Experience multiplier (from Source-Files and Augments)
charisma_exp_mult: Charisma Experience multiplier (from Source-Files and Augments)
company_rep_mult: Company reputation gain multiplier (from Source-Files and Augments)
faction_rep_mult: Faction reputation gain multiplier (from Source-Files and Augments)
money: Current money
city: Name of city you are currently in
location: Name of the last location visited
crime_money_mult: Crime money multiplier (from Source-Files and Augments)
crime_success_mult: Crime success multiplier (from Source-Files and Augments)
isWorking: Boolean indicating whether the player is currently performing work
workType: Name of the kind of work the player is performing
currentWorkFactionName: Name of the faction the player is currently working for
currentWorkFactionDescription: Description of the kind of work the player is currently doing
workHackExpGainRate: Amount of Hacking experience the player will gain every cycle (fifth of a second)
workStrExpGainRate: Amount of Strength experience the player will gain every cycle
workDefExpGainRate: Amount of Defense experience the player will gain every cycle
workDexExpGainRate: Amount of Dexterity experience the player will gain every cycle
workAgiExpGainRate: Amount of Agility experience the player will gain every cycle
workChaExpGainRate: Amount of Charisma experience the player will gain every cycle
workRepGainRate: Amount of Reputation the player will gain every cycle
workMoneyGainRate: Amount of Money the player will gain every cycle
workMoneyLossRate: Amount of Money the player will lose every cycle
workHackExpGained: Total Hacking experience gained while working thus far
workStrExpGained: Total Strength experience gained while working thus far
workDefExpGained: Total Defense experience gained while working thus far
workDexExpGained: Total Dexterity experience gained while working thus far
workAgiExpGained: Total Agility experience gained while working thus far
workChaExpGained: Total Charisma experience gained while working thus far
workRepGained: Total Reputation gained while working thus far
workMoneyGained: Total Money gained while working thus far
createProgramName: Name of the program the player is currently creating
createProgramReqLvl: Hacking skill required to make that program
className: Name of the class the player is currently studying
crimeType: Name of the crime the player last started
work_money_mult: Salary multiplier (from Source-Files and Augments)
hacknet_node_money_mult: Hacknet Node production multiplier (from Source-Files and Augments)
hacknet_node_purchase_cost_mult: Hacknet Node purchase cost multiplier (from Source-Files and Augments)
hacknet_node_ram_cost_mult: Hacknet Node RAM upgrade cost multiplier (from Source-Files and Augments)
hacknet_node_core_cost_mult: Hacknet Node Core purchase cost multiplier (from Source-Files and Augments)
hacknet_node_level_cost_mult: Hacknet Node level upgrade cost multiplier (from Source-Files and Augments)
hasWseAccount: Boolean indicating whether the player has a WSE Account
hasTixApiAccess: Boolean indicating whether the player has TIX API Access
has4SData: Boolean indicating whether the player has 4S Market Data Access
has4SDataTixApi: Boolean indicating whether the player has 4S Market Data TIX API Access
bladeburner_max_stamina_mult: Bladeburner Max Stamina multiplier (from Source-Files and Augments)
bladeburner_stamina_gain_mult: Bladeburner Stamina Gain multiplier (from Source-Files and Augments)
bladeburner_success_chance_mult: Bladeburner Success Chance multiplier (from Source-Files and Augments)
bitNodeN: Current BitNode number
totalPlaytime: Total amount of time the game has been running, in milliseconds
playtimeSinceLastAug: Milliseconds since the last time Augmentations were installed
playtimeSinceLastBitnode: Milliseconds since this BitNode was started
jobs: A mapping of companies the player works for to the title of the player's job at that company
factions: An array of factions the player is currently a member of
tor: Boolean indicating whether or not you have a tor router
}
Example::
player = getPlayer();
print('My charisma level is: ' + player.charisma);

View File

@@ -1,11 +0,0 @@
getPortHandle() Netscript Function
==================================
.. js:function:: getPortHandle(port)
:RAM cost: 10 GB
:param number port: Port number
:returns: portHandle object. See :ref:`netscript_ports`
**WARNING:** Port Handles only work in :ref:`netscriptjs`. They will not work in :ref:`netscript1`.

View File

@@ -1,88 +0,0 @@
getRunningScript() Netscript Function
=====================================
.. js:function:: getRunningScript()
:RAM cost: 0.3 GB
:returns: Script object or null if not found.
The object has the following properties:
.. code-block:: javascript
{
// Script arguments
args
// Script filename
filename
// This script's logs. An array of log entries
logs
// Flag indicating whether the logs have been updated since
// the last time the UI was updated
logUpd
// Total amount of hacking experience earned from this script when offline
offlineExpGained
// Total amount of money made by this script when offline
offlineMoneyMade
// Number of seconds that the script has been running offline
offlineRunningTime
// Total amount of hacking experience earned from this script when online
onlineExpGained
// Total amount of money made by this script when online
onlineMoneyMade
// Number of seconds that this script has been running online
onlineRunningTime
// Process ID.
pid
// How much RAM this script uses for ONE thread
ramUsage
// IP of the server on which this script is running
server
// Number of threads that this script is running with
threads
}
Examples:
.. code-block:: javascript
getRunningScript(); // get the current script.
.. js:function:: getRunningScript(pid)
:RAM cost: 0.3 GB
:param number pid: PID of the script.
:returns: Script object or null if not found.
Examples:
.. code-block:: javascript
getRunningScript(42); // get the script with pid 42.
.. js:function:: getRunningScript(fn, hostname[, args...])
:RAM cost: 0.3 GB
:param number fn: Filename of the target script.
:param number hostname: Hostname of the server running the script.
:param number args...: Arguments that the script is running with.
:returns: Script object or null if not found.
Examples:
.. code-block:: javascript
getRunningScript("example.script", "home", "foodnstuff"); // get the script called "example.script" on "home" with argument "foodnstuff"

View File

@@ -1,17 +0,0 @@
getScriptExpGain() Netscript Function
=====================================
.. js:function:: getScriptExpGain([scriptname[, hostname[, args...]]])
:RAM cost: 0.1 GB
:param string scriptname: Filename of script.
:param string hostname: Server on which script is running.
:param args...: Arguments that the script is running with.
:returns: The amount of hacking experience the specified script generates
while online.
This function can also return the total experience gain rate of all of your
active scripts by running the function with no arguments.
.. note:: A script is uniquely identified by both its name and its
arguments.

View File

@@ -1,19 +0,0 @@
getScriptIncome() Netscript Function
====================================
.. js:function:: getScriptIncome([scriptname[, hostname/ip[, [args...]]])
:RAM cost: 0.1 GB
:param string scriptname: Filename of script
:param string hostname/ip: Server on which script is running
:param args...: Arguments that the script is running with
:returns: Amount of income the specified script generates while online.
If called with no arguments this function will return an array of two
values. The first value is the total income ($ / second) of all of your
active scripts (scripts that are currently running on any server). The
second value is the total income ($ / second) that you've earned from
scripts since you last installed Augmentations.
.. note:: A script is uniquely identified by both its name and its
arguments.

View File

@@ -1,33 +0,0 @@
getScriptLogs() Netscript Function
==================================
.. js:function:: getScriptLogs([filename[, hostname=current hostname[, args...]]])
:RAM cost: 0 GB
:param string filename: Optional. Filename of script to get logs from.
:param string hostname: Optional. Hostname of the server running the script.
:param args...: Arguments to identify which scripts to get logs for
:returns: Array of string, each line being a logged line. Chronological.
.. note:: There is a maximum number of lines that a script stores in its logs.
This is configurable in the game's options.
If the function is called with no arguments, it will return the current
script's logs.
Otherwise, the ``filename``, ``hostname``, and ``args...`` arguments can be
used to get the logs from another script. Remember that scripts are uniquely
identified by both their names and arguments.
Example:
.. code-block:: javascript
// Get logs from foo.script on the current server that was run with no args
getScriptLogs("foo.script");
// Get logs from foo.script on the foodnstuff server that was run with no args
getScriptLogs("foo.script", "foodnstuff");
// Get logs from foo.script on the foodnstuff server that was run with the arguments [1, "test"]
getScriptLogs("foo.script", "foodnstuff", 1, "test");

View File

@@ -1,13 +0,0 @@
getScriptName() Netscript Function
==================================
.. js:function:: getScriptName()
:RAM cost: 0 GB
:returns: Current script name.
Example:
.. code-block:: javascript
getScriptName(); // returns: "example.script"

View File

@@ -1,28 +0,0 @@
getServerBaseSecurityLevel() Netscript Function
===============================================
.. js:function:: getServerBaseSecurityLevel(hostname)
:RAM cost: 0.1 GB
:param string hostname: Hostname of target server.
:returns: Base security level of target server.
The base security level is the security level that the server starts out with.
This function isn't particularly useful.
:doc:`getServerSecurityLevel<getServerSecurityLevel>` and
:doc:`getServerMinSecurityLevel<getServerMinSecurityLevel>` are more often
used.
Example:
.. code-block:: javascript
getServerBaseSecurityLevel('foodnstuff'); // returns: 9
.. note:: This is different than :doc:`getServerSecurityLevel<getServerSecurityLevel>`
because :doc:`getServerSecurityLevel<getServerSecurityLevel>` returns the current
security level of a server, which can constantly change due to
:doc:`hack<hack>`, :doc:`grow<grow>`, and :doc:`weaken<weaken>` calls on
that server. The base security level will stay the same until you reset
by installing augmentation(s).

View File

@@ -1,19 +0,0 @@
getServerGrowth() Netscript Function
====================================
.. js:function:: getServerGrowth(hostname)
:RAM cost: 0.1 GB
:param string hostname: Hostname of target server.
:returns: Server growth parameter.
The growth parameter is a number, typically between 1 and 100, that affects
the percentage by which the server's money is increased when using the
:doc:`grow<grow>` function. A higher growth parameter will result in a
higher percentage increase.
Example:
.. code-block:: javascript
getServerGrowth('foodnstuff'); // returns: 5

View File

@@ -1,25 +0,0 @@
getServerRam() Netscript Function
=================================
.. js:function:: getServerRam(hostname)
.. warning:: This function is deprecated. It still functions, but new
scripts should prefer :doc:`getServerMaxRam<getServerMaxRam>`
and :doc:`getServerUsedRam<getServerUsedRam>` instead.
:RAM cost: 0.1 GB
:param string hostname: Hostname of target server.
:returns: An array of 2 numbers; the first number is the total RAM, and the
second is the used RAM.
Returns an array with two elements that gives information about a server's memory (RAM). The first
element in the array is the amount of RAM that the server has total (in GB). The second element in
the array is the amount of RAM that is currently being used on the server (in GB).
Example:
.. code-block:: javascript
res = getServerRam("helios"); // returns: [5, 10]
totalRam = res[0];
ramUsed = res[1];

View File

@@ -1,13 +0,0 @@
getTimeSinceLastAug() Netscript Function
========================================
.. js:function:: getTimeSinceLastAug()
:RAM cost: 0.05 GB
:returns: Milliseconds since you last installed augmentations.
Example:
.. code-block:: javascript
getTimeSinceLastAug(); // returns: 13912400

View File

@@ -1,21 +0,0 @@
getWeakenTime() Netscript Function
==================================
.. js:function:: getWeakenTime(hostname[, hackLvl=current level])
:RAM cost: 0.05 GB
:param string hostname: Hostname of target server.
:returns: seconds it takes to execute the :doc:`weaken<weaken>` Netscript
function on the target server.
The function takes in an optional *hackLvl* parameter that can be specified
to see what the weaken time would be at different hacking levels.
Example:
.. code-block:: javascript
getWeakenTime("foodnstuff"); // returns: 34.5
.. note:: For Hacknet Servers (the upgraded version of a Hacknet Node), this function will
return :code:`Infinity`.

View File

@@ -20,8 +20,7 @@ grow() Netscript Function
server will be increased by a certain, fixed percentage. This percentage is
determined by the target server's growth rate (which varies between servers)
and security level. Generally, higher-level servers have higher growth
rates. The :doc:`getServerGrowth<getServerGrowth>` function can be used to
obtain a server's growth rate.
rates.
Like :doc:`hack<hack>`, :doc:`grow<grow>` can be called on any server, from
any server. The :doc:`grow<grow>` command requires root access to the target

View File

@@ -1,24 +0,0 @@
growthAnalyze() Netscript Function
==================================
.. js:function:: growthAnalyze(hostname, growthAmount[, cores])
:RAM cost: 1 GB
:param string hostname: Hostname of server to analyze.
:param number growthAmount: Multiplicative factor by which the server is
grown. Decimal form. Must be >= 1.
:param number cores: Amount of cores on the server that would run the growth, defaults to 1
:returns: The amount of :doc:`grow<grow>` threads needed to grow the specified
server by the specified amount.
Example:
.. code-block:: javascript
// How many grow threads are needed to double the current money on 'foodnstuff'
growthAnalyze("foodnstuff", 2); // returns: 5124
If this returns 5124, then this means you need to call :doc:`grow<grow>`
5124 times in order to double the money (or once with 5124 threads).
**Warning**: The value returned by this function isn't necessarily a whole number.

View File

@@ -1,22 +0,0 @@
hackAnalyzePercent() Netscript Function
=======================================
.. js:function:: hackAnalyzePercent(hostname)
:RAM cost: 1 GB
:param string hostname: Hostname of target server.
:returns: The percentage of money you will steal from the target server with
a single hack.
Returns the percentage of the specified server's money you will steal with a
single hack. This value is returned in percentage form, not decimal.
For example, assume the following returns 1:
.. code-block:: javascript
hackAnalyzePercent("foodnstuff"); // returns: 1
This means that if hack the 'foodnstuff' server, then you will steal 1% of its
total money. If you :doc:`hack<hack>` using N threads, then you will steal N% of its total
money.

View File

@@ -1,37 +0,0 @@
hackAnalyzeThreads() Netscript Function
=======================================
.. js:function:: hackAnalyzeThreads(hostname, hackAmount)
:RAM cost: 1 GB
:param string hostname: Hostname of server to analyze.
:param number hackAmount: Amount of money you want to hack from the server.
:returns: The number of threads needed to :doc:`hack<hack>` the server for
``hackAmount`` money.
This function returns the number of script threads you need when running
the :doc:`hack<hack>` command to steal the specified amount of money from
the target server.
If ``hackAmount`` is less than zero or greater than the amount of money
available on the server, then this function returns -1.
For example, let's say the 'foodnstuff' server has $10m and you run:
.. code-block:: javascript
hackAnalyzeThreads("foodnstuff", 1e6);
If this function returns 50, this means that if your next :doc:`hack<hack>` call
is run on a script with 50 threads, it will steal $1m from the `foodnstuff` server.
.. warning:: The value returned by this function isn't necessarily a whole number.
.. warning:: It is possible for this function to return :code:`Infinity` or :code:`NaN` in
certain uncommon scenarios. This is because in JavaScript:
* :code:`0 / 0 = NaN`
* :code:`N / 0 = Infinity` for 0 < N < Infinity.
For example, if a server has no money available and you want to hack some positive
amount from it, then the function would return :code:`Infinity` because
this would be impossible.

View File

@@ -1,16 +0,0 @@
hackChance() Netscript Function
===============================
.. js:function:: hackChance(hostname)
:RAM cost: 1 GB
:param string hostname: Hostname of target server.
:returns: The chance you have of successfully hacking the target server.
in decimal form.
Example:
.. code-block:: javascript
hackChance("foodnstuff"); // returns: .5
// So 50% chance to hack "foodnstuff"

View File

@@ -1,22 +0,0 @@
nFormat() Netscript Function
============================
.. js:function:: nFormat(n, format)
:RAM cost: 0 GB
:param number n: number to format
:param string format: The format to use.
Converts a number into a string with the specified format. This uses the
`numeraljs <http://numeraljs.com/>`_ library, so the formatters must be
compatible with that.
The game uses the ``$0.000a`` format to display money.
Example:
.. code-block:: javascript
nFormat(1.23e9, "$0.000a"); // returns: "$1.230b"
nFormat(12345.678, "0,0"); // returns: "12,346"
nFormat(0.84, "0.0%"); // returns: "84.0%"

View File

@@ -1,14 +0,0 @@
peek() Netscript Function
=========================
.. js:function:: peek(port)
:RAM cost: 1 GB
:param number port: Port to peek. Must be an integer between 1 and 20.
:returns: First element on that port.
This function is used to peek at the data from a port. It returns the first
element in the specified port without removing that element. If the port is
empty, the string "NULL PORT DATA" will be returned.
Read about how :ref:`netscript_ports` work here

View File

@@ -1,23 +0,0 @@
prompt() Netscript Function
===========================
.. js:function:: prompt(txt)
:RAM cost: 0 GB
:param string txt: Text to appear in the prompt dialog box.
:returns: ``true`` if the player clicks "Yes".
Prompts the player with a dialog box with two options: "Yes" and "No". This
function will return true if the player click "Yes" and false if the player
clicks "No". The script's execution is halted until the player selects one
of the options.
Example:
.. code-block:: javascript
cost = getPurchasedServerCost(8192);
answer = prompt("Buy a server for $"+cost);
if(answer) {
purchaseServer("my server", 8192);
}

View File

@@ -1,21 +0,0 @@
read() Netscript Function
=========================
.. js:function:: read(portOrFilename)
:RAM cost: 1 GB
:param string/number portOrFilename: Port or text file to read from.
This function is used to read data from a port, a text file (.txt), or a
script (.script, .js, .ns).
If the argument ``portOrFilename`` is a number between 1 and 20, then it
specifies a port and it will read data from that port. Read about how
:ref:`netscript_ports` work here. A port is a serialized queue. This
function will remove the first element from that queue and return it. If the
queue is empty, then the string "NULL PORT DATA" will be returned.
If the argument ``portOrFilename`` is a string, then it specifies the name
of a text file or script and this function will return the data in the
specified text file/script. If the text file does not exist, an empty string
will be returned.

View File

@@ -1,13 +0,0 @@
rm() Netscript Function
=======================
.. js:function:: rm(filename[, hostname=current server])
:RAM cost: 1 GB
:param string filename: Filename of file to remove. Must include the extension.
:param string hostname: Hostname address of the server on which to delete
the file. Optional. Defaults to current server
:returns: ``true`` if it successfully deletes the file.
Removes the specified file from the current server. This function works for
every file type except ``.msg`` files.

View File

@@ -1,8 +0,0 @@
sprintf() Netscript Function
============================
.. js:function:: sprintf()
:RAM cost: 0 GB
See `this link <https://github.com/alexei/sprintf.js>`_ for details.

View File

@@ -1,17 +0,0 @@
tFormat() Netscript Function
============================
.. js:function:: tFormat(milliseconds[, milliPrecision=false])
:RAM cost: 0 GB
:param number milliseconds: Amount of milliseconds to format.
:param number milliPrecision: Display time with millisecond precision.
:returns: milliseconds in the "D M H S" format
Example:
.. code-block:: javascript
tFormat(3000); // returns: "3 seconds"
tFormat(10000000); // returns: "2 hours 46 minutes 40 seconds"
tFormat(10000023, true); // returns: "2 hours 46 minutes 40.023 seconds"

View File

@@ -1,58 +0,0 @@
tail() Netscript Function
==================================
.. js:function:: tail([fn[, hostname=current hostname[, ...args]])
:RAM cost: 0 GB
:param string fn: Optional. Filename of script to get logs from.
:param string hostname: Optional. Hostname of the server that the script is on.
:param args...: Arguments to identify which scripts to get logs for.
Opens a script's logs. This is functionally the same as the
:ref:`tail_terminal_command` Terminal command.
If the function is called with no arguments, it will open the current script's logs.
Otherwise, the ``fn``, ``hostname``, and ``args...`` arguments can be
used to get the logs from another script. Remember that scripts are uniquely
identified by both their names and arguments.
Example:
.. code-block:: javascript
// Open logs from foo.script on the current server that was run with no args
tail("foo.script");
// Open logs from foo.script on the foodnstuff server that was run with no args
tail("foo.script", "foodnstuff");
// Open logs from foo.script on the foodnstuff server that was run with the arguments [1, "test"]
tail("foo.script", "foodnstuff", 1, "test");
.. js:function:: tail(scriptPid)
:RAM cost: 0 GB
:param number scriptPid: PID of the script to tail.
Opens a script's logs by pid
Example:
.. code-block:: javascript
// Open logs from process with id 42
tail(42);
.. js:function:: tail()
:RAM cost: 0 GB
Opens the current script logs.
Example:
.. code-block:: javascript
// Open the current script logs.
tail();

View File

@@ -1,17 +0,0 @@
toast() Netscript Function
============================
.. js:function:: toast(message[, variant])
:RAM cost: 0 GB
:param string message: message to display
:param success|info|warning|error variant: color of the toast
Spawns a toast (those bottom right notifications, like "Game Saved!" ).
Example:
.. code-block:: javascript
toast("Reached $1b");
toast("Failed to hack home", "error");

View File

@@ -1,17 +0,0 @@
tprint() Netscript Function
===========================
.. js:function:: tprintf(format, args...)
:RAM cost: 0 GB
:param format: Format of the string to be printed.
:param args: Values to be formatted
Prints a raw formatted string to the terminal.
Example:
.. code-block:: javascript
tprintf("Hello world!"); // Prints "Hello world!" to the terminal.
tprintf("Hello %s", "world!"); // Prints "Hello world!" to the terminal.

View File

@@ -1,14 +0,0 @@
tryWrite() Netscript Function
=============================
.. js:function:: tryWrite(port, data="")
:RAM cost: 1 GB
:param number port: Port to be written to
:param string data: Data to try to write
:returns: ``true`` if the data is successfully written to the port.
Attempts to write data to the specified Netscript Port. If the port is full,
the data will not be written. Otherwise, the data will be written normally.
See :ref:`netscript_ports` for more details.

View File

@@ -1,8 +0,0 @@
vsprintf() Netscript Function
=============================
.. js:function:: vsprintf()
:RAM cost: 0 GB
See `this link <https://github.com/alexei/sprintf.js>`_ for details.

View File

@@ -1,31 +0,0 @@
wget() Netscript Function
=========================
.. js:function:: wget(url, target[, hostname=current hostname])
:RAM cost: 0 GB
:param string url: URL to pull data from
:param string target: Filename to write data to. Must be script or text file
:param string ip: Optional hostname of server for target file.
Retrieves data from a URL and downloads it to a file on the specified server. The data can only
be downloaded to a script (.script, .ns, .js) or a text file (.txt). If the file already exists,
it will be overwritten by this command.
Note that it will not be possible to download data from many websites because they do not allow
cross-origin resource sharing (CORS). Example::
wget("https://raw.githubusercontent.com/danielyxie/bitburner/master/README.md", "game_readme.txt");
**IMPORTANT:** This is an asynchronous function that returns a Promise. The Promise's resolved
value will be a boolean indicating whether or not the data was successfully
retrieved from the URL. Because the function is async and returns a Promise,
it is recommended you use ``wget`` in :ref:`netscriptjs`.
In NetscriptJS, you must preface any call to
``wget`` with the ``await`` keyword (like you would ``hack`` or ``sleep``).
``wget`` will still work in :ref:`netscript1`, but the functions execution will not
be synchronous (i.e. it may not execute when you expect/want it to). Furthermore, since Promises are not
supported in ES5, you will not be able to process the returned value of ``wget`` in
Netscript 1.0.

View File

@@ -1,26 +0,0 @@
write() Netscript Function
===========================
.. js:function:: write(portOrFilename, data="", mode="a")
:RAM cost: 1 GB
:param string/number portOrFilename: Port or text file/script that will be written to
:param string data: Data to write
:param string mode: Defines the write mode. Only valid when writing to text files or scripts.
This function can be used to either write data to a port, a text file
(.txt), or a script (.script, .js, .ns)
If the first argument is a number between 1 and 20, then it specifies a port
and this function will write ``data`` to that port. Read about how
:ref:`netscript_ports` work here. The third argument, ``mode``, is not used
when writing to a port.
If the first argument is a string, then it specifies the name of a text file
or script and this function will write ``data`` to that text file/script. If
the specified text file/script does not exist, then it will be created. The
third argument ``mode``, defines how the data will be written. If ``mode``
is set to "w", then the data is written in "write" mode which means that it
will overwrite all existing data on the text file/script. If ``mode`` is set
to any other value then the data will be written in "append" mode which
means that the data will be added at the end of the file.