3. How Does It Work? <<< Contents >>> 5. Peter's Garden
Let us start to create our own program. First, we have to create a new, empty program. In the program window (the window that appears after Peter starts), click the third button from the left . If you rest the mouse pointer over the button before clicking it, a small window with the word New appears, and the quick help in the bottom part of the window says Creates a new program. After clicking the button, you will be prompted to enter the new program name. Type Test and press Enter.
Peter creates a new, empty program called Test, and opens it for editing. You will see the program editor, as we described it in the previous chapter, only the editing window will be empty.
In the Global Variables and Functions window (upper left), a group called basic variables and functions is prepared. This group contains several basic elements. You can change them, but cannot delete them. We will describe the elements one after another.
The first element is called main program function. It contains the program as such, and is empty when new program is created. The text besides the icon is the main function name.
Notice the arrow to the left of the main function icon: . The arrow identifies the element that is currently being edited, that is, the element displayed in the editing window. You can edit an element by double-clicking its icon.
The main program function has two interesting properties: (1.) Its icon is also the main icon of the program. You see this icon in Peters program window, as well as in (e.g.) Windows Explorer. (2.) The main function name will be displayed in the title bar of the program. In new programs, the main function name is preset to the program name (Test in our example).
You can change the main function icon (or any other icon) by clicking the Icon button. The name of the main function or any other element can be changed by clicking the Description button. Before you edit an element, select it by clicking its icon. You can also modify the descriptive text by pressing Alt+Enter, or by clicking the text beside the selected element. A little frame with a blinking cursor appears. After you change the text, press Enter. The Esc key returns the text to its original state. When you are changing the text for more elements in a row, you can move the editing frame with the up and down arrow keys, and only press Enter on the last element.
The element under the main program function is called sheet . If you double-click its icon, a green sheet separated by blue lines opens in the editing window. The grid of the blue lines serves only for your orientation on the sheet, and you can turn it off by clicking the Raster button. The sheet separated into green squares remains displayed. The sheet in the basic variables and functions group represents (unlike other sheets) also the running programs window sheet, and it is called main sheet.
The contents of the squares are called items. Items are pictures with the size of 32x32 points. Changing the items on the main sheet squares also changes the contents displayed on the sheet. This way, you can create various animations.
Under the main sheet, there is an empty square element. This item fills every new sheet. Double click the empty square to edit it. Draw something into the square, and switch to the main sheet editing. Notice that all the squares on the sheet have changed.
The last two elements are labeled Peter and Lucy . Double-click Peters icon. Several pictures of Peter in different positions and directions appear. To be precise, there are four rows, each containing five pictures. Such an element is called a sprite. A sprite is a moving animated object, such as the rabbit, which we can move around the window sheet. Later, we will learn how to change Peters and Lucys appearance by changing the sprite.
Now, let us look at the upper right window. It is called Basic Elements, Trash, and it contains all of the Peter development environment commands and features necessary for creating programs. The trash is a supplementary feature of this window. Here you can move all the elements that you dont need.
Now we can start "writing" our first program command. Start editing the main program function by double-clicking its icon (the icon labeled Test). In Basic Elements, expand the first icon from top with the Peter picture. You will see commands used for controlling the Peter character.
Click the step element, and drag it into the editing window. This means: Click the left mouse button on the elements icon, and while holding the button, move the mouse over the editing window. Notice that under the pointer, there is a transparent picture of the element you are dragging and its text. On the bottom edge of the pointer, there are two white overlaying rectangles. These indicate that the element will be copied, i.e. the original element will remain in its location, and a copy of the element will appear in the new location. Try to move the mouse behind the editing window. A black struck circle appears on the bottom edge of the pointer, indicating that you cannot drop the element here. Return to the editing window and release the mouse button. The element appears in the upper left corner of the window.
This way, we created the first command. Nevertheless, this will not be enough for us, and we will create four such commands. It is not necessary to drag them again from the Basic Elements; we can duplicate three times the command that is already in the window. We will drag the elements similarly to dragging from the Basic Elements, but this time, we will use the right mouse button, and we will drop the elements one under another. The right mouse button always copies the elements. The left mouse button moves the elements into a new place. Between the editor windows, you can only copy the elements, no matter which button you use.
When there are four step elements, one under another, our first program is ready. Now we just have to run it. This is done using the Start button. It is the first button from the left on the toolbar. When you click the button, a program window filled with a green sheet appears. Peter the rabbit is in the bottom left corner. He makes a few steps to the right, and the program closes. It is a great program, isnt it?
We only don't like one detail. It is the fact that the program closes immediately. For this reason, we will add a command that will wait for a key to be pressed. It can be found in the controls group, the keyboard subgroup, and it is labeled key input (waits to be pressed) . Add this element behind all of the commands. The whole program will look like this:
Run the program. The rabbit goes to the right again, and waits there. The program will close when you press any key.
Our first program is done. It cannot do much, but it is our own program. Moreover, what is most interesting it is a fully 32-bit Windows multitasking application. What does it mean? You can run the program as many times as you want to, and all of the programs will run at the same time. Advanced users can use Windows Explorer to look into Peters programs working folder (usually C:\My Documents\Peter\Program). Here you can find the Test.exe program, which you can share with your friends, or create an icon for it on the Windows desktop. The program is not dependent on the Peter environment in any way, and you can use it just like any other Windows program.
After our first successful steps, in fact, Peters steps ("Thats one small step for a rabbit, one giant leap for mankind" does that ring a bell?), we can enthusiastically go on experimenting.
Besides the step command, you have probably noticed other commands for controlling Peter, such as turning to the left, right, and back. Try to modify the program, so that Peter makes a small circle and returns to his original place. The result should look like this:
Does it work? Congratulations, you have just become a programmer.
3. How Does It Work? <<< Contents >>> 5. Peter's Garden