Bitburner – Autocomplete Your Scripts in VS Code!

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.

Autocomplete Your Scripts in VS Code!

All credit goes to Pobiega!

How to Do It

  1. Create a new empty folder/directory for your scripts.
  2. Go to the games official github, and download the “NetscriptDefinitions.d.ts” file.
  3. Put this file in your script directory.
  4. Rename the file to “index.d.ts”.
  5. Open the folder in VS Code.
  6. Make a new file for your new script. In this example, we’ll call it “hack.js”.
  7. You now have two options…

Both options do the same thing, but different ways. Pick your poison.

Option 1: JSDoc Params

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();
}

Option 2: JSDoc Type

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();
}
Volodymyr Azimoff
About Volodymyr Azimoff 13938 Articles
I love games and I live games. Video games are my passion, my hobby and my job. My experience with games started back in 1994 with the Metal Mutant game on ZX Spectrum computer. And since then, I’ve been playing on anything from consoles, to mobile devices. My first official job in the game industry started back in 2005, and I'm still doing what I love to do.

Be the first to comment

Leave a Reply

Your email address will not be published.


*