trace( [message,] [skip] )

Returns a description of the current call stack as a string.

Adds the given string to the top of the trace report. Defaults to blank.
Number of levels of the stack to skip. Defaults to 1, to skip the trace() call's own level.
Undocumented feature
This article describes a feature that is not mentioned in the official Pico-8 documentation. The feature was known to work at the time the article was written, but it may be removed or changed in a future version.

The trace() function returns a description of the current call stack as a string. This string is long, and is only useful when printed to a terminal window with printh().

As of Pico-8 v0.1.6, the string includes useless information referring to internal details. For example, if the cart uses the game loop, this stack trace includes the hidden _mainloop function.

Examples Edit

Here's a simple program that counts up to 30, prints the stack trace to the console, then stops.

v = 0
function next()
  if v > 30 then
  return v + 1
function _update()
  v = next()
function _draw()
  print(v, 0, 0, 7)

As of Pico-8 v0.1.11g, the console output shows the trace as follows:

stack traceback:
	[string "-- pico-8 header..."]:7: in function 'next'
	[string "-- pico-8 header..."]:14: in function '_update'
	[string "-- pico-8 header..."]:31: in function '_mainloop'
	[string "-- pico-8 header..."]:38: in main chunk

See also Edit