(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

ParameterTypeMandatoryNotesWarzone Version
value

Variant

(tick)

The value to assert as truthy.

3.2
messageString(tick)

A message to associate with the assertion.

Note: You can specify multiple strings as additional parameters.

3.2

Return value

ValueTypeNotesWarzone Version
undefinedUndefinedThe function does not return anything if value is truthy.3.2
<error>ErrorThe 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?");
This function is likely to be changed in the future. 
Availability 3.2+

Requires:

  • Warzone 3.2 or above
Contents

Jump to:

See also

Related articles:

  • Error Handling – catch the JS error if desired
  • debug() – print a message to system console without triggering a game assertion or JS error

Add-on APIs:

  • Test API – unit testing framework for Warzone Javascripts
  • Util API – its out() function supports assertions