Bitburner

Bitburner

View Stats:
error in script
Hello, im write external function and when im trying to call it, its send error.

i think it didnt like this 'ns[file.toLowerCase()](hostName);' but idk why

Code:
var files = ['BruteSSH', 'FTPCrack', 'HTTPWorm', 'relaySMTP', 'SQLInject']; for (var k = 0; k < files.length; k++) { var file = files[k]; if (ns.fileExists(file+'.exe', 'home')) { ns[file.toLowerCase()](hostName); } }

error
RUNTIME ERROR money-checker.ns@home Dynamic RAM usage calculated to be greater than initial RAM usage on fn: hackAnalyzeChance. This is probably because you somehow circumvented the static RAM calculation. Threads: 1 Dynamic RAM Usage: 3.35GB Static RAM Usage: 3.30GB 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']; Sorry :(

is it bug?
Last edited by KaK igrat v dotu?; Dec 12, 2021 @ 8:14pm
Originally posted by hydroflame:
The problem is this line here

ns[file.toLowerCase()](hostName);

You can't do map access on the ns object. It's a special rule about this game.

You have to do specifically

ns.brutessh
ns.ftpcrack

etc.

You could also simple add this to the top of the function

ns.brutessh;ns.ftpcrack;ns.relaysmtp;ns.httpworm;ns.sqlinect

just so that the game recognizes that you WILL eventually call these functions and calculate the correct ram cost for your script.

It's an annoying side effect of the game mechanics.
< >
Showing 1-7 of 7 comments
KaK igrat v dotu? Dec 12, 2021 @ 8:18pm 
i can send full files if it needed
hydroflame  [developer] Dec 13, 2021 @ 7:49am 
`ns[file.toLowerCase()](hostName);`
This is not ok. There is a mechanism that makes you pay ram but using map access avoids it. So the game detects that and throws an error.
KaK igrat v dotu? Dec 13, 2021 @ 10:13am 
im not trying avoid ram abuse
im just trying to start external function

thats external part of script, weach im trying to start from another script

scripts.ns
export async function getAccessedServersList(ns, hostsList) { var hostListWithAccess = []; for (var i = 0; i < hostsList.length; i++) { var hostName = hostsList;
var serverHackReq = ns.getServerRequiredHackingLevel(hostName);
var myHackLVL = ns.getHackingLevel();

if (!ns.hasRootAccess(hostName)) {
ns.print('INFO: trying to get root.');

var files = ['BruteSSH', 'FTPCrack', 'HTTPWorm', 'relaySMTP', 'SQLInject'];
//var filess = ['brutessh', 'ftpcrack', 'httpworm', 'relaysmtp', 'sqlinject'];

for (var k = 0; k < files.length; k++) {
var file = files[k];
//ns.print('INFO: file:' + file + '.exe exist:' + ns.fileExists(file+'.exe', 'home'));

if (ns.fileExists(file+'.exe', 'home')) {
//ns.eval('ns.'+file.toLowerCase()+'('+hostName+')');
//var fSName = file.toLowerCase();
ns[file.toLowerCase()](hostName);
//eval('ns.scan');
//ns[]
//ns.eval
}
}

if (ns.fileExists('BruteSSH.exe', 'home')) {
ns.brutessh(hostName);
}
if (ns.fileExists('FTPCrack.exe', 'home')) {
ns.ftpcrack(hostName);
}
if (ns.fileExists('HTTPWorm.exe', 'home')) {
ns.httpworm(hostName);
}
if (ns.fileExists('relaySMTP.exe', 'home')) {
ns.relaysmtp(hostName);
}
if (ns.fileExists('SQLInject.exe', 'home')) {
ns.sqlinject(hostName);
}

try {
ns.nuke(hostName);
ns.print('INFO: ' + hostName + ' access');
} catch {
ns.print('ERROR: ' + hostName + ' not access');
continue;
}
}
if (ns.hasRootAccess(hostName) && serverHackReq <= myHackLVL) {
hostListWithAccess.push(hostName);
}
}

return hostListWithAccess;
}[/code]

and im start from another script
import * as sc from "scripts.ns"; export async function main(ns) { var exampleServersList = ['zer0','n00dles','silver-helix']; var serversWithAccess = sc.getAccessedServersList(ns,exampleServersList); ns.print(serversWithAccess); }

try it
KaK igrat v dotu? Dec 13, 2021 @ 10:14am 
or you mean, i cant get access to fnc from map?
The author of this thread has indicated that this post answers the original topic.
hydroflame  [developer] Dec 13, 2021 @ 10:18am 
The problem is this line here

ns[file.toLowerCase()](hostName);

You can't do map access on the ns object. It's a special rule about this game.

You have to do specifically

ns.brutessh
ns.ftpcrack

etc.

You could also simple add this to the top of the function

ns.brutessh;ns.ftpcrack;ns.relaysmtp;ns.httpworm;ns.sqlinect

just so that the game recognizes that you WILL eventually call these functions and calculate the correct ram cost for your script.

It's an annoying side effect of the game mechanics.
Last edited by hydroflame; Dec 13, 2021 @ 10:20am
KaK igrat v dotu? Dec 13, 2021 @ 10:23am 
oh ok, thx)
you do really nice game)
In-sight- Dec 13, 2021 @ 5:29pm 
One way around this is you can force your script to "pay the price" for each of those functions by including at some point:

const _discard = [ns.brutessh, ns.ftpcrack, ns.httpworm, ns.relaysmtp, ns.sqlinject];
You'll notice the "RAM cost" of your script goes up.

Now you should be able to run
ns[file.toLowerCase()](hostName);
because the "static RAM cost" of those functions have been registered somewhere in the program, so it doesn't matter how you access them anymore - as long as it knows in advance you will be using them.
Last edited by In-sight-; Dec 13, 2021 @ 5:30pm
< >
Showing 1-7 of 7 comments
Per page: 1530 50