Advertisement
Kesseleth

server_list.ns

Sep 29th, 2018
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. export async function serverAppend(serverList, toAppend) {
  2.     //for each server in toAppend
  3.     ns.tprint("it gets this far at least");
  4.     toAppend.forEach(function(item, index, array) {
  5.  
  6.         //if serverList does not contain the new server
  7.         if (serverList.includes(item)) {
  8.             ns.tprint("already in there");
  9.         }
  10.         else {
  11.             ns.tprint("oh no");
  12.         }
  13.        
  14.     });
  15.  
  16.     //then add the new server to serverList
  17.    
  18. }
  19.  
  20.  
  21.  
  22. export async function main(ns) {
  23.     let serverList = [];
  24.     //test: serverList will have the scan values in it already
  25.     serverList.splice(0, 5, 1, 2, 3, 4, 5);
  26.     ns.write(1, [1, 2, 3, 4, 5]);
  27.     {
  28.         //While true
  29.         while (true) {
  30.             //Check port 1 for more servers
  31.             if (ns.peek(1) == "NULL PORT DATA") {
  32.                 ns.tprint(ns.peek(1));
  33.             } else {
  34.             //If there are more servers in port 1
  35.             //call the serverAppend function
  36.             ns.tprint("theres something in there");
  37.             let serversToRead = ns.read(1);
  38.             serverAppend(serverList, serversToRead);
  39.                
  40.             }
  41.             //wait 30 seconds        
  42.            await ns.sleep(2000);
  43.         }
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement