bitburner-src/doc/source/netscript/advancedfunctions/autocomplete.rst

40 lines
1.3 KiB
ReStructuredText
Raw Normal View History

2021-10-15 18:47:43 +02:00
autocomplete() Netscript Function
2021-11-18 01:56:17 +01:00
=================================
2021-10-15 18:47:43 +02:00
2021-10-17 04:36:49 +02:00
.. warning:: This feature is not officially supported yet and the API might change. It is also only supported in ns2
2021-10-15 18:47:43 +02:00
.. js:function:: autocomplete(data, args)
:RAM cost: 0 GB
:param Object data: general data about the game you might want to autocomplete.
:param string[] args: current arguments. Minus `run script.js`
2021-10-15 18:47:43 +02:00
data is an object with the following properties::
{
servers: list of all servers in the game.
txts: list of all text files on the current server.
scripts: list of all scripts on the current server.
2021-10-17 04:36:49 +02:00
flags: the same flags function as passed with ns. Calling this function adds all the flags as autocomplete arguments
2021-10-15 18:47:43 +02:00
}
2021-10-17 04:36:49 +02:00
This function is special as it must be declared as a top level function like `main`.
2021-10-15 18:47:43 +02:00
Example:
.. code-block:: javascript
export function autocomplete(data, args) {
return [...data.servers]; // This script autocompletes the list of servers.
return [...data.servers, ...data.scripts]; // Autocomplete servers and scripts
return ["low", "medium", "high"]; // Autocomplete 3 specific strings.
}
Terminal:
2021-11-18 01:56:17 +01:00
.. code-block:: bash
2021-10-15 18:47:43 +02:00
$ run demo.js mega\t
2021-10-15 18:47:43 +02:00
// results in
$ run demo.js megacorp