Add ns.printf function

Behaviour is consistent with that of tprintf versus tprint and
should be equivalent to ns.print(ns.sprintf(...))
This commit is contained in:
Terrana
2022-01-21 11:34:10 +00:00
parent 07fe3c1906
commit f2c4109211
3 changed files with 18 additions and 0 deletions
+6
View File
@@ -722,6 +722,12 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
}
workerScript.print(argsToString(args));
},
printf: function (format: string, ...args: any[]): void {
if (typeof format !== "string") {
throw makeRuntimeErrorMsg("printf", "First argument must be string for the format.");
}
workerScript.print(vsprintf(format, args));
},
tprint: function (...args: any[]): void {
if (args.length === 0) {
throw makeRuntimeErrorMsg("tprint", "Takes at least 1 argument.");