Bitburner Scripts for Dummies

Bitburner Scripts for Dummies

Metadata


Bitburner Scripts for Dummies image 1

Metadata is basically data that cannot be derived by database or mathematical function. I’ve built out a metadata structure for lookup of a company’s server or stock symbol to company name or server name or visa versa. This is data that cannot be derived from the game itself directly. I’ve included all companies as well as their servers and stock symbols. Think of it as kind of an in-memory mini database for a script. All you need is one property of a company and you can look up its other two properties. Many of the following scripts require this data to function properly. I recommend integrating it to your own scripts as it is very useful and it takes some effort to create a functioning metadata structure.

To us the metadata, simply add this line to the very top of your script outside of the main() function:

import { companyMeta } from '/scripts/companyMeta.js';

Now to access the data, you can use these example blocks of code:

for (const company of companyMeta) { let companyName = company.companyName; let serverName = company.serverName; let stockSymbol = company.stockSymbol; … the rest of your code … }

To do a search in Metadata you can use:

const company = companyMeta.find(company => company.stockSymbol === stockSumbol);

Just substitute what property you're looking up for ‘company.stockSymbol’ and replace ‘stockSumbol’ with the property to search for.

To sort the array of companies by max money you can use this block of code:

for (const company of companyMeta) { // Add the company’s max money to the company’s structure if (company.serverName != 'NoServer') company.maxMoney = ns.getServerMaxMoney(company.serverName); } let orderedCompanies = companyMeta.sort((a, b) => { return b.maxMoney - a.maxMoney; });

And to display it you would do:

for (const company of orderedCompanies) { ns.tprint(`Company: ${company.companyName}`); ns.tprint(`Max Money: ${company.maxMoney}`); }

or

orderedCompanies.forEach((company) => {ns.tprint(`${company.companyName} ${company.maxMoney}`);

You can download the complete Bitburner Company Metadata script from Github:

https://github.com/zacstarfire/bitburner/blob/main/scripts/companyMetadata.js

Function Library


Bitburner Scripts for Dummies image 19

A Function Library is a library of functions common to a group of programs to avoid duplicating code and provide a central file for ease of maintenance. lib.js currently only contains 2 functions for formatting displayed money correctly, but I’m sure it will grow in time as I produce more complex scripts.

https://github.com/zacstarfire/bitburner/blob/main/scripts/lib.js

Overview Upgrade


Bitburner Scripts for Dummies image 23

Server Monitor


Bitburner Scripts for Dummies image 25

Improved Stock Trader With Stock Growing


Bitburner Scripts for Dummies image 27

UNDER CONSTRUCTION

I'm currently working on this guide. Come back soon to see it's completion.

Source: https://steamcommunity.com/sharedfiles/filedetails/?id=2874771586					

More Bitburner guilds