assert( cond, [message] )
Causes a runtime error if a conditional expression is false.
The conditional expression to assert.

A message to print when the assertion fails.

You use assert() to confirm that your program is behaving as you expect it to at a specific point in the code. If the conditional expression evaluates to false, assert() triggers a runtime error, and PICO-8 stops the program and reports the error and line number of the assert.

As of PICO-8 v0.1.11, assert() can take an optional message that replaces the default message "assertion failed".

Caution: As of PICO-8 v0.1.6, a runtime error in a coroutine aborts the coroutine but does not report the error. See coresume().

Examples Edit

function divide(num, denom)
  assert(denom != 0, 'cannot divide by zero')
  return num/denom
print(divide(12, 4))  -- 3
print(divide(7, 0))   -- runtime error, assertion failed

See also Edit

Community content is available under CC-BY-SA unless otherwise noted.