TI-Basic 89 Programming/A Basic Program
This page is designed to give you a little glimpse into the future of exactly what TI-89 BASIC is capable of performing. The following program is a game that displays a number on the screen and moves it around for 10 seconds. The object of the game is to memorize that number and then input it.
At first, the program in its entirety will be given (so that you have a chance to copy it to your calculator and test out what it does for yourself). Then, each block of code will be explained as to what it does so that you can get an idea of what it does. Before delving into the details of how it works, however, it may be best to finish reading the rest of this book so that you understand how the syntax and structure works.
This program is called "memory." If you wish to create it in your own calculator, go into the program editor, which can be reached by the following key presses: APPS+7+3. Make sure that the drop down is set to "program" and name it "memory" (a-lock should already be on, so you do not need to press the alpha button).
Also, this program was designed for the TI-89 and TI-89 Titanium. TI-92, TI-92+, and Voyager 200 may have different screen sizes or key mappings, and as such that will prevent this program from working correctly. If you would like to test this program and you have the TI-92, TI-92+, or Voyager 200, please leave a message on the talk page with the screen resolution in pixels (horizontal x vertical) and what number the ENTER (or equivilant) key maps to.
Just a quick reference on some of the characters you will encounter here (again for the TI-89 and TI-89 Titanium):
- © can be created by pressing ♦ + )
- & can be created by pressing ♦ + × (the multiplication key)
- ≤ can be created by pressing ♦ + <
- ≥ can be created by pressing ♦ + >
- Text can be copied by pressing ♦ + ↑ (the shift key to capitalize text)
- Text can be pasted by pressing ♦ + ESC
The spaces after the colons are for readability only, it does not affect anything if you remove them.
This section details how the above program works, broken down piece by piece. It may be best to read the rest of this book before reading this section, as basic structures and functionality will not be explained thoroughly here.
This defines the name of the program, what parameters it takes when called, specifies that it is a Program (not a Function), and tells the catalog listing help that the first parameter is a NUMBER.
This turns off the first five functions on the graph screen, so that they will not be re-drawn while the program is running. Then, if the given number is too large (above 12) or too small (below 1), an error text box is displayed and the program execution is stopped
This takes the floor of the given number (makes in an integer), so that only a whole amount of numbers gets displayed on screen. Then, it clears the I/O screen and Graph of all text/functions/drawings, and turns off the Coordinates, Grid, and Axes on the Graph so that the Graph screen is completely blank.
This initializes all of the variables. x is the number that will be displayed on-screen, so the first four lines (ending with the EndWhile) are a loop to make sure that x is of the correct length. z is how many pixels that the text will move in any one direction. a and b specify the direction the text is moving. a specifies vertical movement, so a value of -1 means it moves upwards, 0 means it does not move vertically, and 1 means it moves downwards. b specifies horizontal movement, so a value of -1 means it moves left, 0 means it does not move horizontally, and 1 means it moves right. c is a counter that increments by 1 every time the number moves one pixel. d and e are the vertical and horizontal starting points of the number (respectively).
This puts the number on the screen at the d and e coordinates from the above snippet. Then, it draws a horizontal line at the bottom of the screen. This line is the status bar for how much time the player has remaining to memorize the number being displayed.
This sets p at 0 (p is being used as a counter to see how to progress the status bar), then starts a loop that runs 51 times. At the beginning of the loop, a check is made for a keypress on the calculator's key pad. If the "ENTER" key is pressed, the loop is cut short and the part of the program where the user must type in the memorized number executes. Otherwise, it removes 3 or 4 pixels from the end of the status bar (3 normally, 4 if y -- the counter for the loop -- is evenly divisible by 10).
This checks if the text has moved z pixels in the current direction, and if it has the text direction changes.
The beginning of this code is what actually "moves" the text. Two checks are made for both d (the vertical coordinate) and e (the horizontal coordinate) to make sure that the text hasn't moved to a spot where it would no longer be visible in its entirety. Then, it displays the text padded by spaces so that the previous text gets overwritten (instead of leaving a trail behind). After it displays the text, it either continues executing the loop or stops if the loop counter is 50.
This wipes the graph screen (so one cannot simply toggle back to it to see the number), then asks on the I/O screen for the number. Different text will display if the player inputs it correctly or incorrectly. Then, it asks if the player would like to try again. If they agree, it jumps back to the line saying "Lbl a". If they do not agree, it displays the home screen then stops program execution