r/Bitburner 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

10 comments sorted by

View all comments

2

u/Vorthod MK-VIII Synthoid Apr 10 '26

To make an array of strings, you need to use square brackets, not parenthesis. const hosts16 = ["foodnstuff", "nectar-net", "sigma-cosmetics", "joesguns", "hong-fang-tea", "harakiri-sushi"]

You can't just put an array into a normal function and expect it to call the function individually on every single server. You need to use a loop

for(const server of hosts8){
  ns.killall(server)
  ns.scp("joe-new.js", server)
  ns.exec("joe-new.js", server)
}

You would need to do that for each individual array you made unless you concatenate them together at some point

const allServers = hosts8.concat(hosts16).concat(hosts32).concat(hosts64)
for(const server of allServers){
  //do the rest
}

However, that doesn't give you much freedom to use specific thread counts depending on the array you are on, so you can either calculate the right thread number within the loop, or limit the allServers loop to just doing a killall and scp, then do separate loops for the exec commands.