diff --git a/src/ActiveScriptsUI.js b/src/ActiveScriptsUI.js index 2110d9602..d41d63a26 100644 --- a/src/ActiveScriptsUI.js +++ b/src/ActiveScriptsUI.js @@ -5,9 +5,9 @@ import {workerScripts, import {Player} from "./Player"; import {getServer} from "./Server"; import {dialogBoxCreate} from "../utils/DialogBox"; -import {printArray, - createAccordionElement, removeElement, +import {createAccordionElement, removeElement, removeChildrenFromElement} from "../utils/HelperFunctions"; +import {arrayToString} from "../utils/helpers/arrayToString"; import {createElement} from "../utils/uiHelpers/createElement"; import {exceptionAlert} from "../utils/helpers/exceptionAlert"; import {logBoxCreate} from "../utils/LogBox"; @@ -112,7 +112,7 @@ function addActiveScriptsItem(workerscript) { //Threads, args, kill/log button panel.appendChild(createElement("p", { innerHTML: "Threads: " + workerscript.scriptRef.threads + "
" + - "Args: " + printArray(workerscript.args) + "Args: " + arrayToString(workerscript.args) })); var panelText = createElement("p", { innerText:"Loading...", fontSize:"14px", diff --git a/src/NetscriptEvaluator.js b/src/NetscriptEvaluator.js index 515f65694..1a6c56c07 100644 --- a/src/NetscriptEvaluator.js +++ b/src/NetscriptEvaluator.js @@ -9,7 +9,7 @@ import {Script, findRunningScript, RunningScript} from "./Script"; import {parse, Node} from "../utils/acorn"; -import {printArray} from "../utils/HelperFunctions"; +import {arrayToString} from "../utils/helpers/arrayToString"; import {isValidIPAddress} from "../utils/helpers/isValidIPAddress"; import {isString} from "../utils/helpers/isString"; @@ -872,7 +872,7 @@ function runScriptFromScript(server, scriptname, args, workerScript, threads=1) } else { //Able to run script if(workerScript.disableLogs.ALL == null && workerScript.disableLogs.exec == null && workerScript.disableLogs.run == null && workerScript.disableLogs.spawn == null) { - workerScript.scriptRef.log("Running script: " + scriptname + " on " + server.hostname + " with " + threads + " threads and args: " + printArray(args) + ". May take a few seconds to start up..."); + workerScript.scriptRef.log("Running script: " + scriptname + " on " + server.hostname + " with " + threads + " threads and args: " + arrayToString(args) + ". May take a few seconds to start up..."); } var runningScriptObj = new RunningScript(script, args); runningScriptObj.threads = threads; diff --git a/src/NetscriptFunctions.js b/src/NetscriptFunctions.js index 1c11ed774..f5f8df91d 100644 --- a/src/NetscriptFunctions.js +++ b/src/NetscriptFunctions.js @@ -48,7 +48,8 @@ import {NetscriptPort} from "./NetscriptPort"; import Decimal from "decimal.js"; import {dialogBoxCreate} from "../utils/DialogBox"; -import {printArray, powerOfTwo} from "../utils/HelperFunctions"; +import {powerOfTwo} from "../utils/HelperFunctions"; +import {arrayToString} from "../utils/helpers/arrayToString"; import {createRandomIp} from "../utils/IPAddress"; import {formatNumber, isHTML} from "../utils/StringHelperFunctions"; import {isString} from "../utils/helpers/isString"; @@ -686,18 +687,18 @@ function NetscriptFunctions(workerScript) { } var runningScriptObj = findRunningScript(filename, argsForKillTarget, server); if (runningScriptObj == null) { - workerScript.scriptRef.log("kill() failed. No such script "+ filename + " on " + server.hostname + " with args: " + printArray(argsForKillTarget)); + workerScript.scriptRef.log("kill() failed. No such script "+ filename + " on " + server.hostname + " with args: " + arrayToString(argsForKillTarget)); return false; } var res = killWorkerScript(runningScriptObj, server.ip); if (res) { if (workerScript.disableLogs.ALL == null && workerScript.disableLogs.kill == null) { - workerScript.scriptRef.log("Killing " + filename + " on " + server.hostname + " with args: " + printArray(argsForKillTarget) + ". May take up to a few minutes for the scripts to die..."); + workerScript.scriptRef.log("Killing " + filename + " on " + server.hostname + " with args: " + arrayToString(argsForKillTarget) + ". May take up to a few minutes for the scripts to die..."); } return true; } else { if (workerScript.disableLogs.ALL == null && workerScript.disableLogs.kill == null) { - workerScript.scriptRef.log("kill() failed. No such script "+ filename + " on " + server.hostname + " with args: " + printArray(argsForKillTarget)); + workerScript.scriptRef.log("kill() failed. No such script "+ filename + " on " + server.hostname + " with args: " + arrayToString(argsForKillTarget)); } return false; } @@ -1978,7 +1979,7 @@ function NetscriptFunctions(workerScript) { } var runningScriptObj = findRunningScript(scriptname, argsForScript, server); if (runningScriptObj == null) { - workerScript.scriptRef.log("getScriptIncome() failed. No such script "+ scriptname + " on " + server.hostname + " with args: " + printArray(argsForScript)); + workerScript.scriptRef.log("getScriptIncome() failed. No such script "+ scriptname + " on " + server.hostname + " with args: " + arrayToString(argsForScript)); return -1; } return runningScriptObj.onlineMoneyMade / runningScriptObj.onlineRunningTime; @@ -2008,7 +2009,7 @@ function NetscriptFunctions(workerScript) { } var runningScriptObj = findRunningScript(scriptname, argsForScript, server); if (runningScriptObj == null) { - workerScript.scriptRef.log("getScriptExpGain() failed. No such script "+ scriptname + " on " + server.hostname + " with args: " + printArray(argsForScript)); + workerScript.scriptRef.log("getScriptExpGain() failed. No such script "+ scriptname + " on " + server.hostname + " with args: " + arrayToString(argsForScript)); return -1; } return runningScriptObj.onlineExpGained / runningScriptObj.onlineRunningTime; diff --git a/src/NetscriptWorker.js b/src/NetscriptWorker.js index d263a0adb..2a5c37228 100644 --- a/src/NetscriptWorker.js +++ b/src/NetscriptWorker.js @@ -16,7 +16,8 @@ import {Settings} from "./Settings"; import {parse} from "../utils/acorn"; import {dialogBoxCreate} from "../utils/DialogBox"; -import {compareArrays, printArray} from "../utils/HelperFunctions"; +import {compareArrays} from "../utils/HelperFunctions"; +import {arrayToString} from "../utils/helpers/arrayToString"; import {roundToTwo} from "../utils/helpers/roundToTwo"; import {isString} from "../utils/StringHelperFunctions"; @@ -319,7 +320,7 @@ function runScriptsLoop() { dialogBoxCreate("Script runtime error:
Server Ip: " + serverIp + "
Script name: " + scriptName + - "
Args:" + printArray(w.args) + "
" + errorMsg); + "
Args:" + arrayToString(w.args) + "
" + errorMsg); w.scriptRef.log("Script crashed with runtime error"); } else { w.scriptRef.log("Script killed"); @@ -379,7 +380,7 @@ function addWorkerScript(runningScriptObj, server) { var ramAvailable = server.maxRam - server.ramUsed; if (ramUsage > ramAvailable) { dialogBoxCreate("Not enough RAM to run script " + runningScriptObj.filename + " with args " + - printArray(runningScriptObj.args) + ". This likely occurred because you re-loaded " + + arrayToString(runningScriptObj.args) + ". This likely occurred because you re-loaded " + "the game and the script's RAM usage increased (either because of an update to the game or " + "your changes to the script.)"); return; diff --git a/src/Terminal.js b/src/Terminal.js index cd04a49ec..43fa57dcd 100644 --- a/src/Terminal.js +++ b/src/Terminal.js @@ -37,7 +37,7 @@ import {containsAllStrings, longestCommonStart, formatNumber} from "../utils/StringHelperFunctions"; import {addOffset} from "../utils/helpers/addOffset"; import {isString} from "../utils/helpers/isString"; -import {printArray} from "../utils/HelperFunctions"; +import {arrayToString} from "../utils/helpers/arrayToString"; import {logBoxCreate} from "../utils/LogBox"; import {yesNoBoxCreate, yesNoBoxGetYesButton, @@ -2035,7 +2035,7 @@ let Terminal = { return; } else { //Able to run script - post("Running script with " + numThreads + " thread(s) and args: " + printArray(args) + "."); + post("Running script with " + numThreads + " thread(s) and args: " + arrayToString(args) + "."); post("May take a few seconds to start up the process..."); var runningScriptObj = new RunningScript(script, args); runningScriptObj.threads = numThreads; diff --git a/utils/HelperFunctions.js b/utils/HelperFunctions.js index 803538325..bb27dc046 100644 --- a/utils/HelperFunctions.js +++ b/utils/HelperFunctions.js @@ -110,10 +110,6 @@ function compareArrays(a1, a2) { return true; } -function printArray(a) { - return "[" + a.join(", ") + "]"; -} - //Returns bool indicating whether or not its a power of 2 function powerOfTwo(n) { if (isNaN(n)) {return false;} @@ -124,7 +120,6 @@ export {sizeOfObject, clearObject, clearEventListeners, compareArrays, - printArray, powerOfTwo, clearEventListenersEl, removeElement, diff --git a/utils/LogBox.js b/utils/LogBox.js index 627bdce22..85df85dd7 100644 --- a/utils/LogBox.js +++ b/utils/LogBox.js @@ -1,5 +1,6 @@ -import {killWorkerScript} from "../src/NetscriptWorker"; -import {printArray, clearEventListeners} from "./HelperFunctions"; +import {killWorkerScript} from "../src/NetscriptWorker"; +import {clearEventListeners} from "./HelperFunctions"; +import {arrayToString} from "./helpers/arrayToString"; $(document).keydown(function(event) { if (logBoxOpened && event.keyCode == 27) { @@ -47,7 +48,7 @@ function logBoxCreate(script) { document.getElementById('log-box-kill-script').style.display = "inline-block"; logBoxOpen(); document.getElementById("log-box-text-header").innerHTML = - logBoxCurrentScript.filename + " " + printArray(logBoxCurrentScript.args) + ":

"; + logBoxCurrentScript.filename + " " + arrayToString(logBoxCurrentScript.args) + ":

"; logBoxCurrentScript.logUpd = true; logBoxUpdateText(); } diff --git a/utils/helpers/arrayToString.ts b/utils/helpers/arrayToString.ts new file mode 100644 index 000000000..3865d642e --- /dev/null +++ b/utils/helpers/arrayToString.ts @@ -0,0 +1,3 @@ +export function arrayToString(a: T[]) { + return `[${a.join(", ")}]`; +}