hackAssert()

(info) Other great resources: Official JS API docs, Scripting Forum

hackAssert()

Assert a value and throw a game assert and JS error if it's falsey...

 

Syntax

There are several syntax options for this function...
hackAssert(value, message);

Parameters

Parameter

Type

Mandatory

Notes

Warzone Version

value

Variant

The value to assert as truthy.

3.2

message

String

A message to associate with the assertion.

Note: You can specify multiple strings as additional parameters.

3.2

Return value

Value

Type

Notes

Warzone Version

undefined

Undefined

The function does not return anything if value is truthy.

3.2

<error>

Error

The value specified was falsey and failed the assertion.

3.2

Notes

The function will evaluate the value as truthey or falsey:

  • truthy – the assertion will pass and the game will continue as normal

  • falsey – the assertion will fail and a game assert will be triggered, followed by a Javascript error

If a debugger is attached to Warzone, when a game assert is thrown Warzone will halt to allow debugging. Otherwise the game will continue running.

An error will be logged to the log file and console (see debug() for platform-specific access to console messages) should the assertion fail.

Example

// this should pass (and do nothing) hackAssert(true, "this should do nothing");   // this should fail (and cause a game assert + JS error) hackAssert(false, "NASDA routine systems test: What could possibly go wrong?");