Bitburner

Bitburner

View Stats:
[SOLVED] SCP Ram issue: What am I missing?
Edit: See my commend below. Don't dynamically call RAM using functions. Lessone Learned.

Ok quick synopsis: I have a script that checks if I can nuke a server, does so if possible, then distributes the basic "early hack script" to each available system. Pretty basic stuff from my understanding.

The issue is when I try to expand my reach. After the inital 0 ports, every time I run it, at least 1 system fails to scp the hack script. Running it a second time causes 0 issues; everything cracks, scps, and executes without fail. I cannot figure out what the issue is.

I have tried adding sleeps, and slowing it down to ensure that things aren't overlapping each other. My system atm has 1PB of RAM so it's not my ram that is the issue.

**SIDE NOTE** The error popup always references the "ns.scp" line specifically.

Here is the function that sends the file
async function sendFiles(ns, hostName, filePath) { if (!ns.fileExists(filePath, hostName)) { ns.tprint(` - Uploading file: ${filePath}`); await ns.sleep(500) await ns.scp(filePath, hostName); await ns.sleep(500) ns.tprint(` - Upload Complete`); } }

Here is the script that is being send to the server:
/** @param {NS} ns **/ // hack.js export async function main(ns) { var server_name = ns.args[0]; while (true) { // Check if the current security level is greater than the minimum level if (ns.getServerSecurityLevel(server_name) > ns.getServerMinSecurityLevel(server_name)) { // await ns.weaken(server_name) } else if (ns.getServerMoneyAvailable(server_name) < ns.getServerMaxMoney(server_name)) { await ns.grow(server_name) } else { await ns.hack(server_name) } } }

And this is the error message that I got. This one failed when trying to SCP "hack.js" to Iron-Gym, a system with 32GB of RAM and nothing running on it (It was cracked during this script execution):
sleep: Sleeping for 0.500 seconds. scp: Insufficient static ram available. scp: Dynamic RAM usage calculated to be greater than RAM allocation. This is probably because you somehow circumvented the static RAM calculation. Threads: 1 Dynamic RAM Usage: 4.95GB per thread RAM Allocation: 4.85GB per thread One of these could be the reason: * Using eval() to get a reference to a ns function const myScan = eval('ns.scan'); * Using map access to do the same const myScan = ns['scan']; * Using RunOptions.ramOverride to set a smaller allocation than needed Sorry :( Script crashed due to an error.
Last edited by Wabbadabba™; Mar 30, 2024 @ 7:46am
< >
Showing 1-2 of 2 comments
old_one_15 Mar 29, 2024 @ 5:30pm 
The issue is outside the sendFile function. This is just where the game recognizes there's an issue.

Each in-game function has a RAM cost. This error tells you that you used a function without paying for it. When you go to use ns.scp the cost of the script becomes more than what you paid, so the game throws an error.

Since this is also a nuke script, look at the part of the script that opens ports. There are a few really sensible ways to write a nuke script that don't work because they circumvent the RAM cost. If you see anything resembling the examples in the error, that's probably the problem.
Wabbadabba™ Mar 30, 2024 @ 7:42am 
Originally posted by old_one_15:
The issue is outside the sendFile function. This is just where the game recognizes there's an issue.

Each in-game function has a RAM cost. This error tells you that you used a function without paying for it. When you go to use ns.scp the cost of the script becomes more than what you paid, so the game throws an error.

Since this is also a nuke script, look at the part of the script that opens ports. There are a few really sensible ways to write a nuke script that don't work because they circumvent the RAM cost. If you see anything resembling the examples in the error, that's probably the problem.

wow idk why I missed that. I had made an object of {cmd: filename} that it iterated through to dynamically check and call all 5 files. I turned it into an array and a switch statement and it works perfectly now.

So I went from:
function crackVulnerableHosts(ns, portFiles, hosts) { for (const hostname of hosts) { if (!ns.hasRootAccess(hostname)) { let portsOpened = 0; for (const [crackFunction, fileName] of Object.entries(portFiles)) { if (portsOpened >= ns.getServerNumPortsRequired(hostname)) { break; // Exit the loop if we've opened enough ports } if (ns.fileExists(fileName)) { ns[crackFunction](hostname); portsOpened++; } } if (portsOpened >= ns.getServerNumPortsRequired(hostname)) { ns.nuke(hostname); activityLog(ns, 0, `Gained access to: ${hostname}`); } } } }

to

function crackVulnerableHosts(ns, portFiles, hosts) { for (const hostname of hosts) { if (!ns.hasRootAccess(hostname)) { let portsOpened = 0; for (const fileName of portFiles) { if (portsOpened >= ns.getServerNumPortsRequired(hostname)) { break; // Exit the loop if we've opened enough ports } if (ns.fileExists(fileName)) { switch (fileName) { case 'BruteSSH.exe': ns.brutessh(hostname); case 'FTPCrack.exe': ns.ftpcrack(hostname); case 'relaySMTP.exe': ns.relaysmtp(hostname); case 'HTTPWorm.exe': ns.httpworm(hostname); case 'SQLInject.exe': ns.sqlinject(hostname); } portsOpened++; } } if (portsOpened >= ns.getServerNumPortsRequired(hostname)) { ns.nuke(hostname); activityLog(ns, 0, `Gained access to: ${hostname}`); } } } }
< >
Showing 1-2 of 2 comments
Per page: 1530 50