Game Help (pop)   (link) Game Help

Telling the Computer What to Do

Continue reading below...

HTML5=JavaScript required
Score 0
Choose a (hard to guess) name:

New User  

Computers are mostly programmed (told what to do) by typing text commands into a program. Older computer systems let users do this one line at a time (it's called a command line in Linux) and it seems easy to do. Command lines are really the hard way to program computers, so we will soon learn better ways, but this is a good way to start.

The command line lets you type any command the computer knows how to do, and then the computer will do exactly that one command. Try typing in the name of one of the arrow keys, like "left" or "right" (no quotes) then see what happens when you click the "Do It" button. See if you can guess what command will make the nibbler go up or down.

This gets tiresome pretty quick because it's faster to click the arrow buttons than it is to type commands into the command line. However, each command you type in gets saved in the list on the left (it's called a "script") when you click the "Do It" button, and if you click on the "Do All" button, it will do them all in order. Try it. It's still tiresome, but the beauty of doing it this way is that if you make a mistake, you can correct just your mistake without retyping the whole program again. We make a lot of mistakes, but mostly we only find out later. We'll get into more of that later. For now you can watch it on the screen and see what it did wrong, then fix your script.

Mostly when you type commands in to be added to your script, they go at the end. If you see a mistake, you can type the line number at the front of your line (with a space, like it shows on the listing) and the line will replace that line in the script. If you type only a line number and nothing else, it will delete that line (and renumber the rest to fill in the gap). To insert a line between two existing lines, use a decimal fraction like 2.5 to insert between lines 2 and 3, and it will push lines 3 and following down (and renumber them) to insert your new line 3.

But because I told the computer how to understand the commands you type into it (somebody must tell it how to do everything it knows how to do; that was me today, but next week that will be you.  I can also tell it to let you repeat the same command multiple times. Try "left 3" (with a space before the number) and see what it does. What commands would you type in to make it go all the way to the end of the row then turn and go all the way to the top? When you have multiple commands like this doing some complex sequence of things, it's called a "script" or program. Notice that clicking the Reset button a couple times erases your whole script, but you can Save it and later Restore it.

Click here to learn more about saving...

I put a "Help" link at the top and bottom of each page to explain everything in more detail.

Game Help (link) (ToC) Next >>

Begin Programming Page 0, 2020 February 25