PICO-8 Editor & HELLO WORLD
01/04/21 16:07 Filed in: PICO-8
In the last post I looked at the various SPLORE screens and touched on the command line. In this entry I want to do a quick overview of the PICO-8 development environment and screens.
If not running PICO-8 start it up. If you are still in it after the previous post get back to the command line, then type in:
REBOOT
This will clear out memory and any carts you may have been running. Once you're back at the command line hit the ESC key. This switches between the command line and the integrated development environment (IDE).
This is the source code editor. It's nice for quick-and-dirty testing, but you'll probably want to use your favorite editor. I'll show you how to do that next time. For now, try typing a simple program:
One thing you'll quickly figure out is that if you use the caps or shift key on your keyboard you don't get letters. So, type the program above without using the caps or shift keys. Also, as you'll see there are no lowercase letters. They are all uppercase.
We've written our first PICO-8 program. Now, hit ESC to get back to the command line. Then type
RUN
Woot! It works. If not, get back to the editor by hitting ESC and check your typing.
Let's go through the program. First, anything that starts with — is a comment and ignored by PICO-8, documentation.
There are three required functions:
FUNCTION _INIT()
END
FUNCTION _UPDATE()
END
FUNCTION _DRAW()
END
This is the basic game setup. Note the required underscores.
- _INIT() initializes or sets up your game
- _UPDATE() is called and updates at 30 fps. There is also an _UPDATE60() function that updates at 60 fps. This is where you move your characters and update the state of your game.
- _DRAW() takes the changes you made in _UPDATE() and draws to the screen.
_INIT() is called once when the program starts. _UPDATE() and _DRAW() are called at the requested frame rate (this is your game loop).
FUNCTION and END are keywords that mark the beginning and end of a function (a block of code).
In the _INIT() function I set up a string variable named TXT on line 3. Note there aren't any data type declarations. Line 4 sets up two variables X and Y, the coordinates to draw to. The PICO-8 screen is 128 x128 "pixels". The interesting thing about line 4 is that we can declare more than one variable on a line and just use a space as a separator.
In the _UPDATE() function we don't do anything in this example, so I just have a comment.
In _DRAW() we actually take our TXT string and draw it on the screen. Line 12 clears the screen with the color 1. Here are the colors PICO-8 uses.
Line 14 draws (prints) the TXT string at the position 20,20 (X,Y).
The syntax for the PRINT command is:
PRINT(str, [x,y,[col]])
The x,y coordinates are optional, as is the color.
Try changing the colors and text string. Run it a few times to get a feel for what is going on.
One thing to note here is that this looks pretty boring, but this HELLO THERE string is being animated at 30 fps. We'll play with that in the next few entries.
For now, once you are finished playing, get back to the command line and type:
SAVE HELLO
Then get back into SPLORE and hit the left-arrow key to get you to your carts list. You should see your HELLO program listed.
That's enough for now.