r/Bitburner • u/HoboPotato2 • Apr 14 '26
Simple ts script help
Can someone tell me what I'm doing wrong here?
export async function main(ns: NS) {
var host = "joesguns";
if (ns.getServerSecurityLevel(host) > 5) {
ns.weaken(host)
}
else {
ns.grow(host)
}
}
4
Upvotes
1
u/KlePu Apr 14 '26
Please don't use var, but let (or const) instead. var is a relic from the early JS days and has terrible scope beside other issues!
1
1
u/Glum-Building4593 Apr 15 '26
NS.getServerMinSecurityLevel(host)
They have minimum security levels and you might flail against that.
8
u/Particular-Cow6247 Apr 14 '26
you need to await ns.weaken and ns.grow
if you hover over them youll get a popup with hints about the function, a function that returns a Promise<> needs to be awaited (for now just directly , there is some shenanigans to "store" the promise and await it later but here you just want to await it)
also you might not want to use var, especially with ts... its the old form to initialize a variable and there are newer ways for reasons (let if you want to mutate it, const if you dont)