The program view
At the top of the window, beneath the menu bar, you will see a toolbar with the Program button selected.
Below this, you will see a panel containing a tabbed palette full of icons.
IMAGE:"Wizard tab and palette"
Below this is the program grid where you write your program.
IMAGE:"empty program grid"
Press the World button to see the world view.
Press the Mixed button to see the mixed view.
These three modes of operation allow you to view and modify the world, your program, or both at once.
IMAGE:"Other tab and palette"
Click and drag any icon in the palette downwards to the program grid below. Repeat this with several different icons, dragging them above, below, to the left and right of icons already placed on the program grid. This is how you add elements to your program.
Click on one of the icons you have placed on the program grid and drag it upwards back to the palette. The icon will be removed from the program grid. Repeat this until there are no more icons left on the program grid.
Press the Execute button IMAGE:"Execute button". You will see a new window open with the Little Wizard in it.
IMAGE:"Empty execute window" including window decorations.
The title bar of this window will say "Program finished..." because we haven't yet given the Wizard anything to do in the program grid. Press the close button, which in most window managers appears as an "X" in the upper right corner of the title bar IMAGE:"image of the right end of the title bar showing the close button", to close the execution window. This terminates the program.
Press the World button on the toolbar. Drag the horizontal divider between the icon bar and the world grid IMAGE:"close up of the horizontal divider, with a bit of the window around it for context" until the window looks roughly like the following picture.
"The world view" Click and drag a piece of the house from the icon bar down into the World grid below. Drag some more pieces. Drag them back to the icon bar to remove them. Click on the Digits and Alphabet tabs to reveal more icons that can be placed in the World in the same way.
IMAGE:"Alphabet palette" Click on the Grid button IMAGE:"Grid button" to show grid lines in the World grid, which makes placement of new icons in the grid a bit easier.
IMAGE:"Empty world with grid turned on"
Click on the magnifying glass IMAGE:"magnifying glass" to zoom the view of the world grid out and in. Click on the arrows to add or remove columns IMAGE:"left and right arrows" and rows IMAGE:"up and down arrows" to your world grid.
FIXME: too early to mention this; introduce rows & columns & breaking a line by showing how in a later lesson.
The program can be laid out to multiple rows or all in the same row. The execution will always go from left to right and downwards. The return symbol can be used to break long lines.
Click and drag icons from the palette into the first row of the world grid until it looks like the following picture. You will need to click on the Math tab to find the numbers, and click on the Wizard tab to find the other icons.
"move the wizard"
Press the Execute button to see what happens.
First, the Wizard starts walking in the direction he is already facing, which is to the right. The Wizard will walk two squares because we put the number two after the walk icon. Then the Wizard turns right and walks again, this time downwards. Then the Wizard turns right and walks three squares. The Wizard will end up five steps to the right, one down and will be facing right.
Close the execution window.
If the Wizard didn't do what you expected, go back and change the icons on the program grid so that they are the same as the image shown above and press Execute again. When programs don't do what they should do, we call it a bug. Taking bugs out of your program is called debugging.
FIXME: introduce a deliberate bug and show what happens.
The Wizard is also able to alter his surroundings. He can use the wand, or create command to create items in the world. The command is followed by one or more icons or a number which the Wizard will create as he walks forward.
This is the result of the code above.
He is also able to disappear and reappear at command. Note that there is no delay after the first step and the disappear command afterwards. It will look like he'll stand still in the first cell, disappear, and reappear two steps away.
Can you think of a way to make it appear like the Wizard was blinking in place?
You can alter the speed with which the Wizard walks. 0 is the slowest speed and 9 is lightning fast. Can you see where the X will appear with this program? You won't see the wizard moving to write it, but just walking leisurely forward.
The remaining commands in the Wizard tab are calculate, which will be introduced shortly, and "Be behind" and "Be in front", both of which tell the wizard to walk behind or in front of the world elements. If not told otherwise, the Wizard will hide behind whatever there is in the world.
These commands allow you to do basic arithmetic. The normal precedence rules apply. Multiplication and division will be calculated before addition and subtraction. 5+4*2 is not the same thing as 4+5*2. If in doubt, you can always use parenthesis.
A word about division. The result is always just the quotient of the calculation, meaning that anything after the decimal point will be dropped away. Mod operation will conversely result the remainder.
Numbers can be used as arguments to create just like world elements.
Random numbers can be generated with the hat. This will walk one to five steps forward.
The lowest row has logic operations, which will be introduced in the section on loop and conditional instructions.
Next are the variables. Most of them are generic variables, which can store world elements or numbers. Initializing them is a good idea, though letting them as they are will treat them as zero for most purposes.
Here a part of a wall is assigned to the variable C. This kind of an instruction, which doesn't lead to any Wizard action, will have to start with the calculator command so that he won't get confused.
The variables can be used for arithmetic, too.
An advanced use for variables is as arrays. An index number, starting from one, can be set inside the brackets. Multiple brackets can be used to make multidimensional arrays. The details are left as an exercise, but let's introduce one special variable that uses them.
The world array represents the world. This program will read what is five cells to the right and one down.
Here the letter Q was inserted into the world before running the program, which the Wizard dutifully replicated in front of him.
These are the loop and conditional instructions, can be used to control program execution. They are typically used along with the logic operations previously shown.
Here is a move instruction that will never be followed.
The logic operations can be used to great effect along with the conditionals. Here the condition "A is one and either B or C is one" is satisfied and the Wizard will step forward.
While instruction will repeat the following instructions for as long as the condition is true. Note that nothing will prevent you from doing an infinite loop. Here the Wizard will walk a full circle.
Repeat and until are always used as a pair. They are just like the while loop, except that the condition is checked after each loop, not before. This can be a more natural way to approach loops occasionally.
Since incrementing or decrementing a loop variable by one on each repetition is such a common case, there is a shorthand instruction for just that. This program here will increase L by one each time and will write it down.
It is possible to initialize the loop variable in the for instruction, too.
The twin of the for...to, for...downto will count to the opposite direction.