As of version 1.2, PICO-8 includes a command useful for debugging: printh("string") This command prints a string to the host operating system's console. You can put printh() calls in your code to examine events or state without cluttering the game screen with debugging information.
So how do you see the host operating system's console?
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:
~/pico-8/pico8 |
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:
/Applications/PICO-8.app/Contents/MacOS/pico8 |
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" |
Note that with the Windows version, the prompt appears immediately (the process is forked). PICO-8 output will appear in this window anyway.
Try it out! With PICO-8 running from the console, type this at the PICO-8 prompt:
printh("hello") |
The message appears in the console window (not the PICO-8 window).
(Updated for 1.5.)
Printh doesn't work on Windows. Either log file is needed or something else.
Hi dddaaannn, looks like you worked out how to do it, and then didn't update your post properly. In one sentence you say "Someone help me out here" then in the next sentence you say "Try it out! The message appears in the console window" which is the behaviour you're after. So you got it working.
I came here because I wanted to get log output too, and running it from the command prompt works just as you described.
In the meantime, I made a really simple debug script to output specific values from your code to your p8 program's display (not ideal, but it works better than trying to print values from a random location in code).
First, make a global called "dbg", and set it to nothing.
Then, at the bottom of your _draw() function, put this:
debug(0,120) |
Then at the bottom of your program code, this:
function debug(x,y) print(dbg,x,y) end |
To use it from anywhere in your code, just do "dbg=[value you want to see]", and it'll print guaranteed (rather than guessing if your print([value]) will work depending if it's before or after your cls() is called). You can, of course, add more things to the debug function - in my case, I display memory and cpu usage in there as well as the dbg variable.
@Domarius: At v1.2 the Windows version didn't work. My intent was to say that it worked on OS X and Linux but not Windows. This appears to have been fixed in a subsequent update, so I updated the post. Thanks!
Note: the exe file may be "pico8.exe" and not "pico-8.exe", it won't launch if the hyphen is wrong
As user Felice pointed out in another thread, printh() also outputs to the system's debug stream.
On Windows you can use for example Sysinternal's DebugView to view it.
https://technet.microsoft.com/en-us/sysinternals/debugview.aspx?f=255&MSPPError=-2147217396
thanks @TastyEnchilada! I set up a filter in there so it only shows stuff beginning with INFO, this will help my development time :)
[Please log in to post a comment]