A short guide that describes how to set up autocompletion for the games own code classes inside Visual Studio Code, so you can write your scripts outside of the game.
- Create a new empty folder/directory for your scripts.
- Go to the games official github, and download the “NetscriptDefinitions.d.ts” file: https://github.com/danielyxie/bitburner/blob/dev/src/ScriptEditor/NetscriptDefinitions.d.ts
- Put this file in your script directory.
- Rename the file to “index.d.ts”.
- Open the folder in VS Code.
- Make a new file for your new script. In this example, we’ll call it “hack.js”.
- You now have two options…
Both options do the same thing, but different ways. Pick your poison.
This option uses a JSDoc params tag on every function that uses the `NS` object type.
/** @param {import(".").NS } ns */ export async function main(ns) { // you now have autocomplete for all `ns.` commands. const hackingLevel = ns.getHackingLevel(); }
This option uses a JSDoc type tag on a global `ns` object. This is safe, internally its the same object being reused anyways.
/** @type import(".").NS */ let ns = null; export async function main(_ns) { ns = _ns; // you now have autocomplete for all `ns.` commands. const hackingLevel = ns.getHackingLevel(); }
Thanks to Pobiega for his great guide, all credit to his effort. you can also read the original guide from Steam Community. enjoy the game.
Related Posts:
- Bitburner: Post-BN9 Hacknet Script (V2.2.1)
- Bitburner: Simple Hacknet Manager
- Bitburner: Unorthodox Automation & In-game Modding
- Bitburner: How to Scan Every Server
- Bitburner: Scan/Nuke/Money Script (Working 2022)