Table of Contents | Previous Page | Next PageCopyright Don Sleeth, 1998 ©
![]()
Page 5 - A Complete Program
Load in your work
- From the file menu, open your project named Page4. Then from the file menu select "Save Project As..." and save your project as Page5
In the procedures page, it should look like this
to Square forward 50 right 90 wait 1 forward 50 right 90 wait 1 forward 50 right 90 wait 1 forward 50 right 90 wait 1 endMaking a simple program
- The Command Center makes a perfect place to test instructions and procedures, however, it is not a very user friendly place from which to launch a program. Later we will be making standalone programs that we can put right on a web page and run them, but the Command Center doesn't show on these Presentation Mode finished programs.
What we need is a button right on our program page. On your program page1, click on the button in the toolbox and then click on the blue page. A dialog box pops up. Looking at it you can see that the button is automatically named button1 and all that we are allowed to do is type in an Instruction to be run when someone clicks on the button.
We want to wire this button so it starts our program. Unfortunately the button gets its label from the name of the instruction that we give it. I would rather than it had a separate label property, but we are smart programmers, we can work around that. I want the button to be labeled Start and fortunately there are no built-in procedures with the name Start, so we can make our own.
![]()
In the Instruction box, type Start and click OK. Then drag the button so it fits nice and tight in the bottom left corner.
I suggest you save your work. If you press Ctrl-S, it will save the revised project as Page5.
Now click on the Start button. We get the error message "I don't know how to Start" which is exactly what we are going to teach MicroWorlds now!
Ctrl-F back to the Procedures page. We need to make a Start procedure, to add the word Start to MicroWorlds vocabulary. First I would like to comment of program design. Remember these lessons are to teach you good programming techniques. They are not just to teach you about MicroWorlds or Logo. The computer language C is a favorite professional language and so is C++. Both of these languages, in particular C++, have been designed to help programmers manage the complexity of computer programs and both of these languages start every program's execution at a procedure named main. This means that the first procedure to run is always called main. If you are reading a program in C or C++, you would typically start by looking for the procedure named main. I feel it is a very good convention to follow.
So we will make a Start procedure which will call (run) our Main procedure. Add these to your procedures page and save your work.
to Start Main end to Main cc talkto "t1 repeat 20 [Square] endWe now have a complete program! The first instruction in Main tells MicroWorlds to clear the command center, this is so we know that anu error messages we see are new ones. The next instruction in Main tells MicroWorlds which turtle should perform the actions in the following instructions. It is not necessary to have that instruction when there is only one turtle, but it improves the readability of our program. The third line uses the built-in procedure repeat which requires two inputs, a number indicating how many repetitions and a list of instructions to repeat. We only have one instruction, to make it into a list you just put square brackets around it. We will be talking more about lists later.Try running your program. Try running it in Presentation Mode. Remember, to get out of Presentation Mode, click on the black part of the screen outside of MicroWorlds.
One final bit of house cleaning to do. As this and other programs grow, your procedures page gets very large. So you don't waste time looking for procedures, you should keep them in alphabetical order. I usually do something special with Main to make it particularly easy to find. Here is my Procedures Page:
==================== to Main cc talkto "t1 repeat 20 [Square] end ==================== to Square forward 50 right 90 wait 1 forward 50 right 90 wait 1 forward 50 right 90 wait 1 forward 50 right 90 wait 1 end to Start Main endSave your work
- So that you can continue with this project at another time, please save your work as Page5
.