printh( str, [filename,] [overwrite] )

Prints a string to a console window that is running Pico-8, or to a file or the clipboard.

The string to print.
The name of a file to append the output, instead of printing to the console. If this is the string "@clip", the message replaces the contents of the system clipboard instead of writing to a file.
If filename is provided and is the name of a file and overwrite is true, this overwrites the file. The default is false, which appends the message to the end of the file.

You can use printh() to emit debugging information without printing it on the Pico-8 display. It can emit this output to a command console window, to a file, or to the system clipboard.

Running Pico-8 in a console window Edit

To see the output of printh() in a window, you must run Pico-8 from a command console. How to do this depends on which operating system you're using.

Windows Edit

In Windows, instead of double-clicking the Pico-8 icon, open Command Prompt, then start Pico-8 with the following command:

"\Program Files (x86)\PICO-8\pico8.exe"

The prompt appears immediately, even though Pico-8 is running. printh() output will appear in this window anyway.

Alternatively, create a file in the same folder as pico8.exe named pico8.bat containing this line:

cmd /k start pico8.exe

When you double-click on this file, it opens a Command Prompt window and runs Pico-8. Messages appear in the window, and the window closes automatically when Pico-8 exits.

Mac OS X Edit

In Mac OS X, instead of double-clicking the Pico-8 icon, open Terminal, then start Pico-8 with the following command, adjusting the path to match where you put the app. For example:


Linux Edit

In Linux, you probably already run the pico8 command from a terminal window. If you don't, locate where you put the pico-8/ directory, then run the pico8 command from a terminal window using its full path. For example:


Writing to a file Edit

The printh() function accepts optional arguments that tell it to send its output to a file instead of to the console. This works even if Pico-8 was not invoked from a command console.

To append the message to a file, provide a filename as the second argument. This creates the file if it does not exist.

printh('debug: score='..score, 'scores.txt')

To overwrite an existing file instead of appending to it, provide true as the third argument:

printh('scores', 'scores.txt', true)
printh('------', 'scores.txt')

Writing to the system clipboard Edit

You can tell printh() to put its message on the system clipboard so you can paste it into another program interactively. To do this, provide a filename of '@clip':

printh('collision data: xpos='..xpos..' ypos='..ypos, '@clip')

Each call to printh(..., '@clip') replaces the contents of the system clipboard with the message. It does not append messages to an existing value. As such, you must use the clipboard contents before the next call to printh(..., '@clip').

Examples Edit

t = 0

function _update()
  t = (t + 1) % 30
  printh('t = '..t)

function _draw()
  circfill(t * 3, t * 3, 4, 8)

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.