mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-26 11:10:58 +02:00
Threads are a positive integer (#366)
* Added new positive integer ns validation helper * `run`, `exec`, and `spawn` verify threads as a positive integer. * `run` terminal command also fails if the provided threadcount is not a positive integer. * Removed some references to .script files in various documentation, and removed some of the NS1 example blocks
This commit is contained in:
@@ -38,6 +38,7 @@ import { RamCostConstants } from "./RamCostGenerator";
|
||||
export const helpers = {
|
||||
string,
|
||||
number,
|
||||
positiveInteger,
|
||||
scriptArgs,
|
||||
argsToString,
|
||||
makeBasicErrorMsg,
|
||||
@@ -157,6 +158,15 @@ function number(ctx: NetscriptContext, argName: string, v: unknown): number {
|
||||
throw makeRuntimeErrorMsg(ctx, `'${argName}' should be a number. ${debugType(v)}`, "TYPE");
|
||||
}
|
||||
|
||||
/** Convert provided value v for argument argName to a positive integer, throwing if it looks like something else. */
|
||||
function positiveInteger(ctx: NetscriptContext, argName: string, v: unknown): number {
|
||||
const n = number(ctx, argName, v);
|
||||
if (n < 1 || !Number.isInteger(n)) {
|
||||
throw makeRuntimeErrorMsg(ctx, `${argName} should be a positive integer, was ${n}`, "TYPE");
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
/** Returns args back if it is a ScriptArg[]. Throws an error if it is not. */
|
||||
function scriptArgs(ctx: NetscriptContext, args: unknown) {
|
||||
if (!isScriptArgs(args)) throw makeRuntimeErrorMsg(ctx, "'args' is not an array of script args", "TYPE");
|
||||
|
||||
Reference in New Issue
Block a user