mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-12-22 22:22:26 +01:00
fix typechecking and documentation for attempt
This commit is contained in:
parent
b700b0246b
commit
47d51391e3
@ -33,10 +33,11 @@ export function NetscriptCodingContract(player: IPlayer, workerScript: WorkerScr
|
|||||||
const hostname = ctx.helper.string("hostname", _hostname);
|
const hostname = ctx.helper.string("hostname", _hostname);
|
||||||
const contract = getCodingContract(ctx, "attempt", hostname, filename);
|
const contract = getCodingContract(ctx, "attempt", hostname, filename);
|
||||||
|
|
||||||
|
if (typeof answer !== "number" && typeof answer !== "string" && !Array.isArray(answer))
|
||||||
|
throw new Error("The answer provided was not a number, string, or array");
|
||||||
|
|
||||||
// Convert answer to string.
|
// Convert answer to string.
|
||||||
const answerStr = JSON.stringify(answer);
|
const answerStr = JSON.stringify(answer);
|
||||||
if (answerStr === undefined) throw new Error("The provided answer could not be stringified");
|
|
||||||
|
|
||||||
const creward = contract.reward;
|
const creward = contract.reward;
|
||||||
if (creward === null) throw new Error("Somehow solved a contract that didn't have a reward");
|
if (creward === null) throw new Error("Somehow solved a contract that didn't have a reward");
|
||||||
|
|
||||||
|
2
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
2
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
@ -3222,7 +3222,7 @@ export interface CodingContract {
|
|||||||
* @param opts - Optional parameters for configuring function behavior.
|
* @param opts - Optional parameters for configuring function behavior.
|
||||||
* @returns True if the solution was correct, false otherwise. If the returnReward option is configured, then the function will instead return a string. If the contract is successfully solved, the string will contain a description of the contract’s reward. Otherwise, it will be an empty string.
|
* @returns True if the solution was correct, false otherwise. If the returnReward option is configured, then the function will instead return a string. If the contract is successfully solved, the string will contain a description of the contract’s reward. Otherwise, it will be an empty string.
|
||||||
*/
|
*/
|
||||||
attempt(answer: string[] | number, filename: string, host?: string, opts?: CodingAttemptOptions): boolean | string;
|
attempt(answer: string | number | any[], filename: string, host?: string, opts?: CodingAttemptOptions): boolean | string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the type of a coding contract.
|
* Get the type of a coding contract.
|
||||||
|
Loading…
Reference in New Issue
Block a user