From 2d8401eaaeec51368f6294f107a13ca5beeba2f2 Mon Sep 17 00:00:00 2001 From: Victor Oliveira Date: Mon, 4 Aug 2025 13:25:06 -0300 Subject: [PATCH] Change alert to accept multiple args as other print functions (#2278) --- markdown/bitburner.ns.alert.md | 4 ++-- src/NetscriptFunctions.ts | 13 +++++++++---- src/ScriptEditor/NetscriptDefinitions.d.ts | 4 ++-- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/markdown/bitburner.ns.alert.md b/markdown/bitburner.ns.alert.md index 5772ebcdc..ccdceb3d5 100644 --- a/markdown/bitburner.ns.alert.md +++ b/markdown/bitburner.ns.alert.md @@ -9,14 +9,14 @@ Open up a message box. **Signature:** ```typescript -alert(msg: string): void; +alert(...args: any[]): void; ``` ## Parameters | Parameter | Type | Description | | --- | --- | --- | -| msg | string | Message to alert. | +| args | any\[\] | Value(s) to be alerted. | **Returns:** diff --git a/src/NetscriptFunctions.ts b/src/NetscriptFunctions.ts index 8cd3e1459..453129c33 100644 --- a/src/NetscriptFunctions.ts +++ b/src/NetscriptFunctions.ts @@ -1473,10 +1473,15 @@ export const ns: InternalAPI = { } return runningScript.onlineExpGained / runningScript.onlineRunningTime; }, - alert: (ctx) => (_message) => { - const message = helpers.string(ctx, "message", _message); - dialogBoxCreate(message, { html: true, canBeDismissedEasily: true }); - }, + alert: + (ctx) => + (...args) => { + if (args.length === 0) { + throw helpers.errorMessage(ctx, "Takes at least 1 argument."); + } + const message = helpers.argsToString(args); + dialogBoxCreate(message, { html: true, canBeDismissedEasily: true }); + }, toast: (ctx) => (_message, _variant = ToastVariant.SUCCESS, _duration = 2000) => { diff --git a/src/ScriptEditor/NetscriptDefinitions.d.ts b/src/ScriptEditor/NetscriptDefinitions.d.ts index 0eba5a2af..d4bc7be02 100644 --- a/src/ScriptEditor/NetscriptDefinitions.d.ts +++ b/src/ScriptEditor/NetscriptDefinitions.d.ts @@ -8109,9 +8109,9 @@ export interface NS { /** * Open up a message box. - * @param msg - Message to alert. + * @param args - Value(s) to be alerted. */ - alert(msg: string): void; + alert(...args: any[]): void; /** * Queue a toast (bottom-right notification).