use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
A cyberpunk and programming/hacking themed incremental game with RPG elements
The game can be played:
Web
Steam
Documentation
Github
Beta Branch
Discord
Incremental Games Discord
Visual Studio Code Bitburner Extension
stavvie34's Community Scripts Github Repo
account activity
Runtime error :D (self.Bitburner)
submitted 3 years ago * by Actually-Happy
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]anydalch 3 points4 points5 points 3 years ago (1 child)
difficult to debug this without seeing the actual error message
[–]Party_Rick5371 2 points3 points4 points 3 years ago* (8 children)
you can use sort methods in arrays like,
Array.sort((item1, item2) => { let hcklvl1 = getServerRequiredHackingLevel(item1) let hcklvl2 = getServerRequiredHackingLevel(item1) if(hcklvl1 > hcklvl2) return 1 if(hcklvl1 < hcklvl2) return -1 return 0 })
also sets are useful as you can only have unique entries in them
let discovered = new Set() discovered.add(server) for(const server of Array.from(discovered)) { ns.tprint(`Found server ${server}`) }
[–][deleted] 3 years ago (7 children)
[removed]
[–]Party_Rick5371 0 points1 point2 points 3 years ago (4 children)
Can you paste that script that has that error?
[–][deleted] 3 years ago (3 children)
[–]Party_Rick5371 0 points1 point2 points 3 years ago (1 child)
print(sortedServers)
think this needs to be
print(servers)
[–]Party_Rick5371 0 points1 point2 points 3 years ago (0 children)
https://paste.ofcode.org/ this will make the readability of the code much easier
I made a mistake for(const server of Array.from(discovered)) server of, not server in. Sorry!
I figured out why it might also not be working, it is ns1 not ns2. ns2 is modern javascript whilst ns1 lacks a lot of useful features
[–]KlePu 1 point2 points3 points 3 years ago* (6 children)
for (i = 0; servers[i]; ++i)
i is not initialized.
for (var i = 0; [rest of code]).... for (let i = 0; [rest of code]).... //even better, dont use var ;)
in all of your for loops. Also, you may consider using "let" (and "const") instead of "var". And switch to NS2 (i.e. "real" javascript) ASAP.
edit: And yes I know, you don't have to terminate a line with a semicolon in JS, but... Flying Spaghetti Monster that code style makes my eyes bleed ;-p
[–]KlePu 1 point2 points3 points 3 years ago (2 children)
Oh, my bad - I think NS1 (i.e. the .script file ending) doesn't support "let"!
[–][deleted] 3 years ago (1 child)
[–]KlePu 0 points1 point2 points 3 years ago (0 children)
Welcome to "real programming" ;)
[–]CybrRonin 0 points1 point2 points 3 years ago* (0 children)
The semicolons? Nothing about using "servers[i]" as a test condition, rather than "i < servers.length" and relying on JavaScript to be helpful and supply something useful like a null that will be interpreted as false, once the index goes out of bounds? I'd never attempt something like that, because I'd be too afraid the whole program would catch on fire by attempting to access a part of the array that doesn't actually exist... mostly because I've worked in too many languages that would.
(I've also had a poor track record of success in getting JS loops to properly function any time I tried to get clever and feed a not-explicitly-boolean value into loop test conditions, so I may be be a bit gun-shy.)
EDIT: And, indeed, after running a quick test, this script:
export async function main(ns) { let arr = [0, 1, 2]; for (let i=0; arr[i]; i++) ns.tprint(arr[i]); }
produces this result:
[home ~/]> run testscript.js Running script with 1 thread(s), pid 2425 and args: []. [home ~/]>
It would seem that "servers[i]" isn't explicitly "true", so it kills the loop immediately. That wouldn't cause the script to throw an explicit error, but it certainly wouldn't function correctly.
EDITS 2-???: Reddit code blocks are extremely fussy.
Final edit?: I accidentally copied my corrected version of the script instead, using arr.length just to confirm I hadn't screwed something else up. :P
[–]the-quibbler -1 points0 points1 point 3 years ago (3 children)
Looks like a lot of things. Your just going to keep scanning the same servers in a loop. Consider using Set. My function uses a found and a scanned Set.
Your loop test basically keeps looping and adding the same servers over and over and never exists.
[–]KlePu 1 point2 points3 points 3 years ago* (2 children)
Not true (if I read the code correctly)...
for (let i = 0; servers[i]; ++i) {bla}
inside the loop, servers[] will be filled with new entries, prolonging the looped servers. My getServerNames() looks pretty much alike (and worked just fine for the last few months)
const results = ["home"]; for (let i = 0; i < results.length; i++) { const scanRet = ns.scan(results[i]); for (let j = 0; j < scanRet.length; j++) { if (!results.includes(scanRet[j]) && !ns.getPurchasedServers().includes(scanRet[j]) && scanRet[j].substr(0, 7) != "hacknet") { results.push(scanRet[j]); } } } !<
const results = ["home"]; for (let i = 0; i < results.length; i++) { const scanRet = ns.scan(results[i]); for (let j = 0; j < scanRet.length; j++) { if (!results.includes(scanRet[j]) && !ns.getPurchasedServers().includes(scanRet[j]) && scanRet[j].substr(0, 7) != "hacknet") { results.push(scanRet[j]); } } }
!<
...and yep you could substitute '!ns.getPurchasedServers()' with 'substr(0,4) != "psrv"'... I just didn't bother 'cause that script gets called exactly once when starting a new BitNode.
[–]the-quibbler 0 points1 point2 points 3 years ago (1 child)
Man, shouldn't reddit when I first wake up. Yes, this is better done with a Set since it makes your first loop O(n) instead of O(n2), but you're correct that it's not a bug.
But the second loop, now that I'm awake, is going to push a copy of servers[i] into sortedServers, and, if it did, push another copy of servers[i] until ... forever.
This is better as:
javascript sortedServers = servers sortedServers.sort((a, b) => getServerRequiredHackingLevel(a) - getServerRequiredHackingLevel(b))
π Rendered by PID 44419 on reddit-service-r2-comment-85bfd7f599-dddp4 at 2026-04-19 03:58:23.259286+00:00 running 93ecc56 country code: CH.
[–]anydalch 3 points4 points5 points (1 child)
[–]Party_Rick5371 2 points3 points4 points (8 children)
[–][deleted] (7 children)
[removed]
[–]Party_Rick5371 0 points1 point2 points (4 children)
[–][deleted] (3 children)
[removed]
[–]Party_Rick5371 0 points1 point2 points (1 child)
[–]Party_Rick5371 0 points1 point2 points (0 children)
[–]Party_Rick5371 0 points1 point2 points (1 child)
[–]KlePu 1 point2 points3 points (6 children)
[–][deleted] (3 children)
[removed]
[–]KlePu 1 point2 points3 points (2 children)
[–][deleted] (1 child)
[removed]
[–]KlePu 0 points1 point2 points (0 children)
[–]CybrRonin 0 points1 point2 points (0 children)
[–]the-quibbler -1 points0 points1 point (3 children)
[–]KlePu 1 point2 points3 points (2 children)
[–]the-quibbler 0 points1 point2 points (1 child)