Fandom

Pico-8 Wiki

Assert

162pages on
this wiki
Add New Page
Comments0 Share
assert( cond )

Causes a runtime error if a conditional expression is false.

cond
The conditional expression to assert.

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.

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().

Examples Edit

function divide(num, denom)
  assert(denom != 0)
  return num/denom
end

print(divide(12, 4))  -- 3
print(divide(7, 0))   -- runtime error, assertion failed

See also Edit

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.