Causes a runtime error if a conditional expression is false.
- The conditional expression to assert.
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.
Pico-8's version of
assert() only takes a conditional expression and does not take a custom message.
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().
function divide(num, denom) assert(denom != 0) return num/denom end print(divide(12, 4)) -- 3 print(divide(7, 0)) -- runtime error, assertion failed