r/Bitburner • • Jan 22 '22

Finally finished my control script logs formatting!

Post image
117 Upvotes

37 comments sorted by

4

u/WeAteMummies Jan 22 '22

how do you do the icons?

14

u/guesdo Jan 22 '22

They are just emojis! All Emojis are valid Unicode characters (which JS uses). They are valid in any code as well as in any browser, just do "⏲️ 3 minutes" and it's valid in any string to copy paste them or use your keyboard. I personally use getemoji.com but you can just use the emoji keyboard in windows or mac.

BTW... You can use them in Reddit too! They just won't show up in all clients.🎮 🎲 🎭 🎯

7

u/amroamroamro Jan 22 '22 edited Jan 22 '22

You can also use Unicode escape sequence like:

var str = "\u23F2 3 minutes"

if you like to keep the source files ASCII-compatible, just in case you open the file in an older editor that doesn't support emojis.


I should mention that if the Unicode character lies outside the BMP (i.e code point > 0xFFFF) you'd have to use a UCS-2 surrogate pair to encode it.

Or use ES6 escapes which allows directly using the code point like "\u{1F3AE}" instead of "\uD83C\uDFAE" both of which are equivalent to "🎮" (https://www.fileformat.info/info/unicode/char/1f3ae/index.htm)

1

u/Naive-Store1451 Jan 22 '22

Are you writing them with the Winkey+. (dot)-thing Win10 offers or is there another way I don't know of?

1

u/guesdo Jan 22 '22

I could use that one, but I use getemoji.com so I can search for what I want 😅

3

u/maxnothing Jan 25 '22

Brilliant use of emojis. Why didn't I think of that? Because you're smarter than me. Nice job!

1

u/guesdo Jan 25 '22

😅 thanks

2

u/maxrec97 Jan 23 '22

Looks good! I assume you use the ports to transfer data to your home/a bought server?

4

u/guesdo Jan 23 '22

Yes, I have a control.js file that runs in home and a very basic worker.js script that listens from instructions from control on port 1 and reports back results on port 2.

3

u/[deleted] Jan 29 '22

Since you shared your worker script, would you mind sharing your control script? I would like to use this pair of scripts as a jumping-off point for my own iteration of the same scripts (it's cool for example, that the emojis work correctly, for example, but I don't personally need them), and automating nuking targets, buying servers, distributing the workers to purchased servers and workers and starting the workloads off on all workers would be my goals, assuming those aren't natively part of the script.

1

u/guesdo Jan 29 '22 edited Jan 29 '22

Yeah! I already shared it in here, look for the comments in this thread I shared the basic control script based on the tutorial one.

Edit: Is not in this thread but le me find you and tag you, or else once I get to my computer I can share.

2

u/maxrec97 Jan 23 '22

Wait so you have hacking scripts on all target servers, that script sends updates on port 1, and then the worker on home listrns for that and sends them to your control script on home on port 2? Never used ports so curious, is it possible to send all events on port 1? Is the no issue if 2 things want to write on that port at the same time?

3

u/guesdo Jan 23 '22

Yes, I have a hacking script in all servers (workers) I have root access, even home (2GB RAM per thread). They sit there doing nothing, waiting and reading from port 1 until data comes. They just need an action (hack, grow, weaken) and a target (server) and they attempt whatever job they read from port 1.

Meanwhile, there is another script in home called control, which has the smart logic to scan servers and make decisions of what to do to each target, and writes all of those to port 1, where workers will listen and pick them up.

Once each worker finishes a job, they report the result back by writing on port 2. Control also reads from port 2 eventually to gather those results and print outcomes to the log.

2

u/maxrec97 Jan 23 '22

Ohhh, i didnt expect that. In my setup i still use the one from the docs for hacking, and just scp that to all servers that have ram and money.

How bog is the control script? Ram cost

Wasnt sure if 2 pieces of data on a port would overwrite each other.

4

u/guesdo Jan 23 '22 edited Jan 23 '22

Hmmm between 2.9GB and 3.15GB it changes every time I optimize it, but definitely less than 4GB. The worker is exactly 2GB (base + hack + weaken + grow) and I want to keep it that way so that it can run everywhere (smallest servers after a reset) and scale easily.

Think of ports as queues, first in, first out (FIFO). They do have a limit in the game (which can be configured to a max of 100). Also everything written to a port can be read exactly ONCE, so even if 1000 workers are reading from port 1, any job can only be picked once by any specific worker.

2

u/maxrec97 Jan 23 '22

Wow, thats suprisingly small, so i assume worker script has 4 functions(hack, grow, weaken,report) and control calls the h, g, w functions and those call report function after being done?

Ahh yeah played this other hacking game some time ago where you could only save 1 value to ports, but thanks for explaining!

3

u/guesdo Jan 23 '22

Here is the worker.js script I deploy to all available servers at max threads in case you are interested. It is very basic (as it should be) workers are dumb.

/* 	
    worker.js by github.com/phrozen
    Keep this script at <= 2GB RAM (minimum)
    This way optimize max threads execution
    The decision making comes from control on port 1
    All actions performed report back result on port 2
*/

/** @param {NS} ns **/
export async function main(ns) {
    // Disable excesive logging
    ns.disableLog('sleep');
    // Hoist some variables
    let message, result, wait = 0;
    // Run while control keeps sending messages
    while(message = ns.readPort(1)) {
        // If port empty, wait 2s and try again
        if (message === "NULL PORT DATA") {
            await ns.sleep(1000);
            wait++;
            continue;
        }
        ns.print(`Waited ${ns.tFormat(wait * 1000)} for a new job.`);
        // Get the action to perform and target server
        const {action, server} = JSON.parse(message);
        switch (action) {
            case "hack":
                result = await ns.hack(server);
                break;
            case "grow":
                result = await ns.grow(server);
                break;
            case "weak":
                result = await ns.weaken(server);
                break;
            default:
                ns.print(`Unknown action: <${action}>`);
                continue;
        }
        // Report result back to control
        await ns.writePort(2, JSON.stringify({action, server, result}));
        wait = 0;
    }
}

2

u/maxrec97 Jan 23 '22

thank you for the script, that look svery interesting!

Oh, so often worker nodes hack, weaken, grow the other servers?

so n00dles hacks max-hardware, max hardware hacks ecorp and so on?

3

u/guesdo Jan 23 '22

Yes, your workers are ANY server where you have root access AND have RAM! That includes all corporate NUKEd servers, home and all servers you purchased.

Targets are all those servers you have root access, your hack level is higher than their required hack level AND can hold money (deep web for example can't).

Workers can be targets too and viceversa. Sometimes a server hacks itself 😅

→ More replies (0)

2

u/Mithrandir2k16 Feb 05 '22

New to the game, what's the benefit of distributing workers that hack targets instead of just installing scripts on each rooted server that keep doing grow/weaken/hack on the server they're running on?

→ More replies (12)
→ More replies (1)

1

u/guesdo Jan 23 '22

Yeah, my control it's actually based on the loop algorithm of the docs. But instead of doing the work itself, it sends it to port 1 for a distributed approach.

3

u/Omelet Jan 22 '22

Sick, nice work.