mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-12-18 20:25:45 +01:00
Updated getScriptLogs() Netscript function to be able to get logs from another script
This commit is contained in:
parent
e2b7418780
commit
063c24e739
@ -153,17 +153,37 @@ isLogEnabled
|
||||
getScriptLogs
|
||||
^^^^^^^^^^^^^
|
||||
|
||||
.. js:function:: getScriptLogs()
|
||||
.. js:function:: getScriptLogs([fn], [hostname/ip=current ip], [args...])
|
||||
|
||||
:param string fn: Optional. Filename of script to get logs from.
|
||||
:param string ip: Optional. IP or hostname of the server that the script is on
|
||||
:param args...: Arguments to identify which scripts to get logs for
|
||||
:RAM cost: 0 GB
|
||||
|
||||
Returns the script's logs. The logs are returned as an array, where each
|
||||
Returns a script's logs. The logs are returned as an array, where each
|
||||
line is an element in the array. The most recently logged line is at the
|
||||
end of the array.
|
||||
|
||||
Note that there is a maximum number of lines that a script stores in its logs.
|
||||
This is configurable in the game's options.
|
||||
|
||||
If the function is called with no arguments, it will return the current script's logs.
|
||||
|
||||
Otherwise, the `fn`, `hostname/ip,` and `args...` arguments can be used to get the logs
|
||||
from another script. Remember that scripts are uniquely identified by both
|
||||
their names and arguments.
|
||||
|
||||
Examples::
|
||||
|
||||
// Get logs from foo.script on the current server that was run with no args
|
||||
getScriptLogs("foo.script");
|
||||
|
||||
// Get logs from foo.script on the foodnstuff server that was run with no args
|
||||
getScriptLogs("foo.script", "foodnstuff");
|
||||
|
||||
// Get logs from foo.script on the foodnstuff server that was run with the arguments [1, "test"]
|
||||
getScriptLogs("foo.script", "foodnstuff", 1, "test");
|
||||
|
||||
scan
|
||||
^^^^
|
||||
|
||||
|
@ -507,6 +507,7 @@ let CONSTANTS = {
|
||||
** purchaseTor() now returns true if you already have a TOR router (it used to return false)
|
||||
** getPurchasedServerCost() now returns Infinity if the specified RAM is an invalid amount or is greater than the max amount of RAM (2 ^ 20 GB)
|
||||
** Added purchase4SMarketData() and purchase4SMarketDataTixApi() functions
|
||||
** getScriptLogs() now takes in optional arguments that let you get the logs of another script
|
||||
|
||||
* Stock Market changes:
|
||||
** Stocks now have "maximum prices"
|
||||
|
@ -554,6 +554,22 @@ function NetscriptFunctions(workerScript) {
|
||||
if (fn != null && typeof fn === 'string') {
|
||||
// Get Logs of another script
|
||||
if (ip == null) { ip = workerScript.serverIp; }
|
||||
const server = getServer(ip);
|
||||
if (server == null) {
|
||||
workerScript.log(`getScriptLogs() failed. Invalid IP or hostname passed in: ${ip}`);
|
||||
throw makeRuntimeRejectMsg(workerScript, `getScriptLogs() failed. Invalid IP or hostname passed in: ${ip}`);
|
||||
}
|
||||
|
||||
let argsForTarget = [];
|
||||
for (let i = 2; i < arguments.length; ++i) {
|
||||
argsForTarget.push(arguments[i]);
|
||||
}
|
||||
const runningScriptObj = findRunningScript(fn, argsForTarget, server);
|
||||
if (runningScriptObj == null) {
|
||||
workerScript.scriptRef.log(`getScriptLogs() failed. No such script ${fn} on ${server.hostname} with args: ${arrayToString(argsForTarget)}`);
|
||||
return "";
|
||||
}
|
||||
return runningScriptObj.logs.slice();
|
||||
}
|
||||
|
||||
return workerScript.scriptRef.logs.slice();
|
||||
@ -809,7 +825,7 @@ function NetscriptFunctions(workerScript) {
|
||||
}
|
||||
NetscriptFunctions(workerScript).exit();
|
||||
},
|
||||
kill : function(filename,ip) {
|
||||
kill : function(filename, ip) {
|
||||
if (workerScript.checkingRam) {
|
||||
return updateStaticRam("kill", CONSTANTS.ScriptKillRamCost);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user