mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-26 11:10:58 +02:00
(feat) optional threads argument to netscript functions hack, weaken, grow
This commit is contained in:
committed by
danielyxie
parent
585e1ac7aa
commit
44c26165f4
@@ -155,6 +155,21 @@ export function makeRuntimeRejectMsg(workerScript, msg, exp=null) {
|
||||
return "|"+workerScript.serverIp+"|"+workerScript.name+"|" + msg + lineNum;
|
||||
}
|
||||
|
||||
export function resolveNetscriptRequestedThreads(workerScript, functionName, requestedThreads) {
|
||||
const threads = workerScript.scriptRef.threads;
|
||||
if (!requestedThreads) {
|
||||
return isNaN(threads) || threads < 1 ? 1 : threads;
|
||||
}
|
||||
const requestedThreadsAsInt = requestedThreads|0;
|
||||
if (isNaN(requestedThreads) || requestedThreadsAsInt < 1) {
|
||||
throw makeRuntimeRejectMsg(workerScript, `Invalid thread count passed to ${functionName}: ${requestedThreads}. Threads must be a positive number.`);
|
||||
}
|
||||
if (requestedThreads > threads) {
|
||||
throw makeRuntimeRejectMsg(workerScript, `Too many threads requested by ${functionName}. Requested: ${requestedThreads}. Has: ${threads}.`);
|
||||
}
|
||||
return requestedThreadsAsInt;
|
||||
}
|
||||
|
||||
//Run a script from inside a script using run() command
|
||||
export function runScriptFromScript(server, scriptname, args, workerScript, threads=1) {
|
||||
//Check if the script is already running
|
||||
|
||||
Reference in New Issue
Block a user