r/Bitburner • u/kaoshavoc • 7d ago
why does this ns.cloud.ugradeServer fail
Even though everything seems correct, it always fails and does not buy any upgrades. I have even printed out the values to make sure everything is what I expect it to be and it is. I always keep all servers at the same amount of ram, thus I only check one since they will all be the some. I had a verison of this before where I told it how much ram to buy, but I wanted to change it to tell it how much I wanted to spend which just seemed to make more sense.
/** u/param {NS} ns */
export async function main(ns) {
const maxSpend = ns.args[0];
const server = "cloud-server-";
const costPerGig = 55000;
const numServers = 25;
// calculate how much to buy for each server
const budgetPerServer = maxSpend / numServers;
let gigsPerServer = Math.floor(budgetPerServer / costPerGig)
if(gigsPerServer % 2){ gigsPerServer -= 1}
const currentRamAmount = ns.getServerMaxRam("cloud-server-0");
if(gigsPerServer > currentRamAmount){
for(let i = 0; i < 25; i++){
ns.tprint(gigsPerServer);
if(!ns.cloud.upgradeServer(server + i,gigsPerServer)){ns.tprint("something went wrong");}
else{ns.tprint("purchased ", gigsPerServer, " for " + i);}
}
}
else{
ns.tprint("If you're broke, just say so.");
}
}
/** u/param {NS} ns */
export async function main(ns) {
const maxSpend = ns.args[0];
const server = "cloud-server-";
const costPerGig = 55000;
const numServers = 25;
// calculate how much to buy for each server
const budgetPerServer = maxSpend / numServers;
let gigsPerServer = Math.floor(budgetPerServer / costPerGig)
if(gigsPerServer % 2){ gigsPerServer -= 1}
const currentRamAmount = ns.getServerMaxRam("cloud-server-0")
if(gigsPerServer > currentRamAmount){
for(let i = 0; i < 25; i++){
ns.tprint(gigsPerServer)
if(!ns.cloud.upgradeServer(server + i,gigsPerServer)){ns.tprint("something went wrong");}
ns.tprint("purchased ", gigsPerServer, " for " + i);
}
}
else{
ns.tprint("If you're broke, just say so.");
}
}
5
Upvotes
4
u/kaoshavoc 7d ago
I think I see now. It has to be in powers of 2, not incements of 2. That would make a lot of sense as to why I am getting the error. Also, seems the price does start scaling so I need to rerwite to check actual values. I thought it was always 55,000 per gig.
4
u/wannabe_pixie 7d ago
I don’t know what stage of the game you’re at but at some point you can’t assume that Ram cost is fixed