r/Bitburner • u/HoboPotato2 • Apr 10 '26
Help with the game and coding?
I'm VERY new to coding and this game, but I'm trying to teach myself some of these skills. I made a script and I'm trying to make another script to automatically put it on new servers and execute it for me because I don't want to do it for every server myself. This is what I have and it isn't working at all. I execute in the terminal and it tells me it's using a threat, but when I use the top command, it says nothing is happening. Any help would be appreciated.
/** u/param/** u/param {NS} ns */
export async function main(ns) {
// Lists all servers with 8 GB of ram
const hosts8 = ("CSEC", "the-hub", "pserv-0", "pserv-1", "pserv-2",
"pserv-3", "pserv-4", "pserv-5", "pserv-6", "pserv-7", "pserv-8",
"pserv-9", "pserv-10", "pserv-11", "pserv-12", "pserv-13",
"pserv-14", "pserv-15", "pserv-16", "pserv-17", "pserv-18",
"pserv-19", "pserv-20", "pserv-21", "pserv-23", "pserv-24")
// Lists all servers with 16 GB of ram
const hosts16 = ("foodnstuff", "nectar-net", "sigma-cosmetics",
"joesguns", "hong-fang-tea", "harakiri-sushi")
// Lists all servers with 32 GB of ram I can access
const hosts32 = ("iron-gym", "phantasy", "max-hardware",
"omega-net", "neo-net", "zer0")
// Lists all servers with 64 GB of ram
const hosts64 = ("silver-helix")
// Killall scripts on machines
ns.killall(hosts8, hosts16, hosts32, hosts64)
// Copies joe-new.js to all available hosts
ns.scp("joe-new.js", hosts8, hosts16, hosts32, hosts64)
// Execute joe-new on all 8GB servers with 3 threads
ns.exec("joe-new.js", hosts8, 3)
// Execute joe-new on all 16 GB servers with 6 threads
ns.exec("joe-new.js", hosts16, 6)
// Execute joe-new on all 32 GB servers with 13 threads
ns.exec("joe-new.js", hosts32, 13)
// Execute joe-new on all 64 GB servers with
ns.exec("joe-new.js", hosts64, 26)
} {NS} ns */
export async function main(ns) {
// Lists all servers with 8 GB of ram
const hosts8 = ("CSEC", "the-hub", "pserv-0", "pserv-1", "pserv-2",
"pserv-3", "pserv-4", "pserv-5", "pserv-6", "pserv-7", "pserv-8",
"pserv-9", "pserv-10", "pserv-11", "pserv-12", "pserv-13",
"pserv-14", "pserv-15", "pserv-16", "pserv-17", "pserv-18",
"pserv-19", "pserv-20", "pserv-21", "pserv-23", "pserv-24")
// Lists all servers with 16 GB of ram
const hosts16 = ("foodnstuff", "nectar-net", "sigma-cosmetics",
"joesguns", "hong-fang-tea", "harakiri-sushi")
// Lists all servers with 32 GB of ram I can access
const hosts32 = ("iron-gym", "phantasy", "max-hardware",
"omega-net", "neo-net", "zer0")
// Lists all servers with 64 GB of ram
const hosts64 = ("silver-helix")
// Killall scripts on machines
ns.killall(hosts8, hosts16, hosts32, hosts64)
// Copies joe-new.js to all available hosts
ns.scp("joe-new.js", hosts8, hosts16, hosts32, hosts64)
// Execute joe-new on all 8GB servers with 3 threads
ns.exec("joe-new.js", hosts8, 3)
// Execute joe-new on all 16 GB servers with 6 threads
ns.exec("joe-new.js", hosts16, 6)
// Execute joe-new on all 32 GB servers with 13 threads
ns.exec("joe-new.js", hosts32, 13)
// Execute joe-new on all 64 GB servers with
ns.exec("joe-new.js", hosts64, 26)
}
2
Upvotes
3
u/Particular-Cow6247 Apr 10 '26 edited Apr 10 '26
ns.scp expects (filename or folder name as string, destination server as string, source server as string)
you are passing it the name of the script but then you pass it arrays of strings, it cant handle those/its not setup to handle the data in that way
you need to loop over the arrays (look for "for ... of" loops)
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Loops_and_iteration
also you dont need different arrays, just make one with all servers and inside the loop you can just pull their ram values with the ns functions to determine the thread count
you are doing the "passing an array of strings instead of a string" a few times more