Loading and Saving Programs

This time around I want to look at how data is stored in PICO-8 and how to use an external editor.


Loading Programs


.
Boot up PICO-8 (launch the app). At the prompt, you can do an LS command. LS stands for directory LiSting. If you're familiar with U/Linux, this should be easy. (It's DIR in Windows/DOS). When you type the command you get a list of all the programs you've created and saved.

Screen Shot 2021-01-13 at 9.25.59 AM

If you've been following along, you should see the program HELLO that we created and saved last time. PICO-8 programs have a .P8 extension. There are two ways to load your source file. You can type LOAD HELLO and hit ENTER (I'm going to assume you do this from now on.)

Screen Shot 2021-01-13 at 9.28.05 AM

You can run your program with the RUN command, or you can edit the source code by hitting the ESC key to get into the PICO-8 source editor. We're not going to do that yet. I said there were two ways to load your program. The second way is to use SPLORE. Type SPLORE to get into the explorer, then hit the left-arrow key to get to the listing of your programs (the first screen of SPLORE is a list of your favorites.)


Screen Shot 2021-01-13 at 9.31.16 AM


There's our program HELLO. What's the thing that looks like a folder in the big gray area? That's our program's logo, or start screen. If you look at other programs in SPLORE you'l have seen all sorts of graphics. Where is graphic? We'll show you how to create that soon. Hang tight.

For now, use the arrow keys to highlight HELLO and then hit ENTER to run it.

Screen Shot 2021-01-13 at 9.32.18 AM

Ok, it still works. Your colors will be whatever you used last time. Get back to the command prompt.

Saving Programs



Last time I talked about saving your program using the SAVE command. That saves your program using a .P8 extension. If, however, you tell PICO-8 to save your program using a PNG extension:

SAVE HELLO.PNG

PICO-8 will prompt you with the following:


Screen Shot 2021-01-13 at 9.39.04 AM


This is how you create the graphic for your cart. Run your program (just type RUN), then hit CTR-7. You'll get a red banner that says CAPTURED LABEL IMAGE. Exit back to the command line (ESC) Go back into SPLORE and find your program. There are now two of them! One is the original which has the P8 extension, the second one has a P8.PNG extension. You can use the LS command from the command line to see both.



Screen Shot 2021-01-13 at 9.42.25 AM


But notice, the background is not black, and the folder icon is gone. You may have some text. In mine, I have a solid background. You took a screen shot of animating text, and depending on when you hit CTR-7, will determine the image you get. For me, I caught it in the act of redrawing, so there is no text and the color is off. Once you have real graphics instead of simple text, you'll see real graphics.

These are the basics of loading and saving. PICO-8 has other ways which we'll look at later. First, I want to go into one more topic.

Using Another Editor




This is our source code in the PICO-8 editor.



Screen Shot 2021-01-13 at 9.48.26 AM


As you can see it's a very small program, but it already takes up the entire editor screen (yes, it scrolls when it fills the screen). The built-in editor is nice for quick changes and very simple programs. For anything else we need to use a better editor. You can actually use any editor you like. The way to do this is a bit roundabout, but it makes life easier.

From the command line we need to use the FOLDER command. When you enter this command, PICO-8 will open a folder on your Mac, Windows, or RaspberryPi. The folder contains all of your programs and carts. I'm on my Mac, and this is what I see when I issue the FOLDER command.

Screen Shot 2021-01-13 at 9.53.03 AM


There are our two programs (and the folder I created on my own). You can use any editor you want to open the hello.p8 program. You can edit the program and run int in PICO-8. You can also create programs and store them in this "carts" folder. PICO-8 will find them and use them just as if you had created them using the built-in editor.


When you open hello.p8 in another editor (I'm using BBEdit), you see something weird.


Screen Shot 2021-01-13 at 9.56.25 AM


There is some extra stuff. The first few lines are used by PICO-8

pico-8 cartridge // http://www.pico-8.com
version 29
__lua__
-- hello pico-8


These declare this is a PICO-8 source file cartridge, it's using version 29, the programming language is Lua. It's a simplified version of Lua. If you want to learn more about Lua check out my other blog. And the final line should be the name of your program.


The stuff after your program is information about your carts graphics (__gfx__), sounds, music, etc. I won't dive into that here. But, don't remove these lines, or PICO-8 won't know how to run your programs properly.

Check out your game cart (the file with the PNG extension)

hello.p8

This is more than just an image displayed in SPLORE. This is your entire cart. PICO-8 embeds your source code, graphics, sounds, etc. into the PNG. You can send someone this image or post it online or put it in a tweet and people can drop it into their carts folder and PICO-8 will be able to run your entire program. Very cool feature of PICO-8. You should be able to drag-drop my cart off this webpage and run it.

I may dive into the internals of the PNG format in the future but, for now, that's enough. You now know how to load and save your programs, as well as how to create a true cart, and use an external editor.




This site does not track your information.