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.
filenameis provided and is the name of a file and
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.
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.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:
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
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
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
t = 0 function _update() t = (t + 1) % 30 printh('t = '..t) end function _draw() cls() circfill(t * 3, t * 3, 4, 8) end