The Beginning
page 2
Programming for the Genius-Impaired
A series of lessons for those who want to learn how to create their own Lightwave Plugins with Lscript.

Pick a Number, Any Number

I remember my very first BASIC program, lo these many years ago.

I'd checked out a book from the library (this was somewhat before the World Wide Web, and somewhat after rubbing two sticks together to make fire), and I read the first chapter during study hall.

Chapter one was a simple little game where the computer would pick a number between one and ten, and you would try to guess it. 

By lunch I'd figured it out, and by the time I could track down a computer to run it on, I'd modified it to hurl increasingly naughty insults at you, the longer you took to guess. 

I think that approach holds up pretty well, so let's get cracking. If you've gone through the first exercise (making a peanut butter sandwich), you know that a program is basically just a very specific list of "things-to-do" for the computer. So let's make a rough list of the steps involved in playing the number guessing game.

Making the List

Every game has at least two players (who said Solitaire? ...uh..you're playing against implacable destiny. Shut up.), so the best way to make this list is to play the part of both players, and step through the game, labeling each step either "Player," or "Keeper of the Number" (KotN, to keep it short).

1. KotN: Picks a number between 1 and 10

2. KotN: Says, "I'm thinking of a number between 1 and 10, can you guess it?"

3. Player: "Is the number  ___?" (makes a guess)

4. KotN: Keep track of how many guesses have been made.

5. KotN: Tell the player which guess they are making.

6. KotN: If the player's guess is right, I say "Congratulations! You're right! You guessed it in _____!" (Then quit playing) otherwise:

7. KotN: If the player's guess is to low, say "Your guess is too low," otherwise:

8. KotN: If the Player's guess is too high, say " Your guess is too high," otherwise:

9. Repeat steps 3 through 8 until the player guesses.
 

Whew.  The hard part is over.  Now we just have to translate this into LScript!