TI-Basic Programs/Printable version


TI-Basic Programs

The current, editable version of this book is available in Wikibooks, the open-content textbooks collection, at
https://en.wikibooks.org/wiki/TI-Basic_Programs

Permission is granted to copy, distribute, and/or modify this document under the terms of the Creative Commons Attribution-ShareAlike 3.0 License.

Writing a Program

There are just a few steps to follow in order to write a program onto your TI-83+ or TI-84 calculator using TI-BASIC.

  1. Turn on your calculator and press the PRGM button.
  2. Press the right arrow button twice to move to NEW.
  3. Press Enter to select Create New.
  4. Name the program. If the program is of your own creation, give it whatever name you would like it to have using the letters above each button or any of the numbers 0-9. If you are copying a program from this book, type in the name already given.
  5. Write the code of the program by using the digits and commands found on the calculator and by using the PRGM sub-menus while within the program code. These menus contain lists of many of the most vital programming commands, such as If, Then, End, While, Menu(, and many others. Other helpful menus of commands are the MATH, TEST, and DRAW command lists.

Note: Some of the programs in this book use lower-case letters in their program codes. In order for a TI calculator user to type in lower-case letters you must have MirageOS on your calculator. You must also check the checkbox for Enable Lowercase in Miscellaneous Options on the Options screen within MirageOS. The Options screen can be opened by pressing the ALPHA key in MirageOS. RAOSX is also useful for enabling lowercase letters and other common assembly functions.

For the instructional wikibook on TI-BASIC programming, see TI-Basic Z80 Programming.


Chase

Program Description edit

Chase is a simple yet enjoyable game. In it, players take the role of a "greater-than" symbol (>) who is getting to eat some X's. It is played on the regular typing screen, and there are 6 characters that can move around the screen. One is the player's character, the > sign. Another, the X, is the character that the player is supposed to move towards and eat once he has reached it. The other four, however, are "not-equal-to" symbols (≠) which are vicious and will try to eat the player if they get close enough. Chase has a title screen that draws itself up on the Graph screen through the CSTART program, which must also be on a player's calculator before he can play Chase. The title screen has four options which are:
1) New Game (to start a new game)
2) Continue (to continue a currently saved game)
3) Instructions (to bring up the instructions for Chase)
4) Quit (to leave the program and return to the main screen).

In the Instructions page, much of the above information is covered, as well as other information like which keys are used for the game controls. In the game, the five non-player characters (the four ≠'s and the X) move around on their own, randomly following any of four patterns. For instance, if one of the ≠'s moves a space left, then another will move up, another will move down, and another will move right. Two ≠'s will never move in the same direction as one another in one move. Also, the movement of the X will parallel that of one of the four monsters. The controls that the player uses to move are displayed on the Instructions page. The player can press any of the 9 number keys (1-9) except for the 5 to move his character. For instance, pressing the 7 key will move the player's character up one space and to the left one space, and pressing the 8 key will only move the player's character up one space. This explanation may be difficult to understand but is very easy to figure out by playing the game.

The player's score is displayed in the upper-right corner of the screen throughout the game. Whenever the player eats the X character, one point will be added to his score in the display. Also, the X will disappear and be regenerated somewhere else on the screen. The player's high score is displayed in the Chase title screen every time he starts the game.

One last control is the ENTER key, which pauses/saves the game that you are currently playing. If the player presses it once while he's playing, he can save his game and come back to it whenever he wishes by starting prgmCHASE and choosing option 2, Continue, mentioned above. Also, by pressing the ENTER key twice while playing, once to pause/save the game and then once again, He can resume immediately and play will continue. The effects of this are that all of the variables for things like score and position of each character on the screen are stored and also, the game will regain its regular running speed. Unfortunately, whenever one is running a TI-Basic program that repeats, it will eventually run slower and slower. To avoid or solve this problem when playing Chase, one can use this method of pressing ENTER twice. As stated above, this exits the program and then resumes it again.

Note: The variables used by the calculator to operate Chase are stored in the [J] matrix.

Program Code edit

Notes:

  1. Many of these lines of code can be linked together in one line by just typing a ":" instead of pressing ENTER and typing the next command on the next line. Also, some of the commands displayed here are already linked in this way.
  2. The "¤" found in the command, " :Output(8,3,"-GAME¤SAVED- ", is actually a very small square and it can be found in the CATALOG menu on your calculator. It will be above what looks like a small plus sign (+), near the bottom of the list.
PROGRAM:CHASE
:If Ans=105:1→Y
:{3,9→dim([J]
:[J](1,1→C:[J](1,2→D:[J](1,3→E:[J](1,4→F:[J](2,1→G:[J](2,2→H
:[J](2,3→I:[J](2,4→J:[J](3,1→K:[J](3,2→L:[J](3,3→M:[J](3,4→N
:If 1=Y
:Then
:DelVar Y
:[J](2,5→X
:Goto A
:End
:If 1≠[J](3,5
:0→[J](1,5
:prgmCSTART
:ZStandard
:AxesOn
:If Ans=93
:Then
:[J](2,5→X
:Goto A
:End
:DelVar X
:round(C,0→C:round(D,0→D:round(E,0→E:round(F,0→F:round(G,0→G:round(H,0→H
:round(I,0→I:round(J,0→J:round(K,0→K:round(L,0→L:round(M,0→M:round(N,0→N
:C+round(9rand,0)-round(9rand,0→C:D+round(9rand,0)-round(9rand,0→D
:G+round(4rand,0)-round(4rand,0→G:H+round(4rand,0)-round(4rand,0→H
:I+round(4rand,0)-round(4rand,0→I:J+round(4rand,0)-round(4rand,0→J
:K+round(4rand,0)-round(4rand,0→K:L+round(4rand,0)-round(4rand,0→L
:M+round(4rand,0)-round(4rand,0→M:N+round(4rand,0)-round(4rand,0→N
:Lbl E
:If C<1:1→C:If C>8:8→C:If D<1:1→D:If D>16:16→D:If E<2:2→E:If E>7:7→E
:If F<2:2→F:If F>15:15→F:If G<2:2→G:If G>7:7→G:If H<2:2→H:If H>15:15→H
:If I<2:2→I:If I>7:7→I:If J<2:2→J:If J>15:15→J:If K<2:2→K:If K>7:7→K
:If L<2:2→L:If L>15:15→L:If M<2:2→M:If M>7:7→M:If N<2:2→N:If N>15:15→N
:If C=E and D=F or C=G and D=H or C=I and D=J or C=K and D=L or C=M and D=N
:Then
:D+round(6rand,0)-round(3rand,0→D
:Goto E
:End
:Lbl C
:E+round(9rand,0)-round(9rand,0→E
:F+round(9rand,0)-round(9rand,0→F
:If E<2:2→E:If E>7:7→E:If F<2:2→F:If F>15:15→F
:If E=M and F=N
:Goto C
:Lbl A
:ClrHome
:Disp X
:Output(E,F,"X
:Output(G,H,"≠
:Output(I,J,"≠
:Output(K,L,"≠
:Output(M,N,"≠
:Output(C,D,">
:If C=E and D=F
:Then
:X+1→X
:Goto C
:End
:If C=G and D=H or C=I and D=J or C=K and D=L or C=M and D=N
:Goto D
:getKey
:If Ans=105
:Then
:Output(8,3,"...SAVING...
:C→[J](1,1
:D→[J](1,2
:E→[J](1,3
:F→[J](1,4
:G→[J](2,1
:H→[J](2,2
:I→[J](2,3
:J→[J](2,4
:K→[J](3,1
:L→[J](3,2
:M→[J](3,3
:N→[J](3,4
:X→[J](2,5
:Output(8,3,"-GAME¤SAVED-
:105
:Stop
:End
:If Ans=0
:Goto B
:If Ans=72 and C>1 and D>1
:Then
:C-1→C
:D-1→D
:End
:If Ans=73 and C>1
:C-1→C
:If Ans=74 and C>1 and D<16
:Then
:C-1→C
:D+1→D
:End
:If Ans=82 and D>1
:D-1→D
:If Ans=84 and D<16
:D+1→D
:If Ans=92 and C<8 and D>1
:Then
:C+1→C
:D-1→D
:End
:If Ans=93 and C<8
:C+1→C
:If Ans=94 and C<8 and D<16
:Then
:C+1→C
:D+1→D
:End
:Lbl B
:randInt(1,4
:If Ans=4
:Goto 3
:If Ans=3
:Goto 2
:If Ans=2
:Goto 1
:If F≥2 and G≤7 and J≤15 and K≥2 and N≥2
:Then
:F-1→F
:G+1→G
:J+1→J
:K-1→K
:N-1→N
:Goto A
:End
:Lbl 1
:If E≥2 and H≥2 and I≤7 and L≤15 and M≥2
:Then
:E-1→E
:H-1→H
:I+1→I
:L+1→L
:M-1→M
:Goto A
:End
:Lbl 2
:If F≤15 and G≥2 and J≥2 and K≤7 and N≤15
:Then
:F+1→F
:G-1→G
:J-1→J
:K+1→K
:N+1→N
:Goto A
:End
:Lbl 3
:If E≤7 and H≤15 and I≥2 and L≥2 and M≤7
:Then
:E+1→E
:H+1→H
:I-1→I
:L-1→L
:M+1→M
:End
:Goto A
:Lbl D
:Output(4,2,"YOU GOT EATEN!
:1→[J](3,5
:0→[J](2,5
:If X>[J](1,5
:Then
:Output(5,2,"{Press  enter}
:Pause 
:X→[J](1,5
:Output(4,2,"New high score:
:Output(5,2,"              "    <-- (This close-quote mark is not needed, but
:Output(5,8,[J](1,5                       there must be 14 blank spaces here)


CStart

Program Description edit

CStart is a title screen start-up program which works in conjunction with prgmCHASE. A user must have both programs on their calculator in order to play Chase. When both programs are in place, the user never needs to actually run prgmCSTART, but it must be un-archived while playing Chase so that Chase can access it. The user simply runs prgmCHASE and the program will then link to CStart automatically. CStart doesn't change any part of the actual gameplay of Chase, but it displays a very cool start-up screen. As outlined in the Program Description section for prgmCHASE in this wikibook, the title screen gives the player four options:
1) New Game (to start a new game)
2) Continue (to continue a currently saved game)
3) Instructions (to bring up the instructions for Chase)
4) Quit (to leave the program and return to the main screen)

It also displays a large drawing of the word "CHASE" with the vicious ≠'s as part of the E. It displays the current High Score in the upper-right (which will show 0 if the user has not played before), and an image of a < sign with angry eyes and sharp teeth chasing a frightened X in order to eat him.

Choice 3 will clear the screen and draw up page 1 of the instructions for Chase. This page gives an introduction and a background for Chase and tells the player what his goal is. The program will be paused when this screen is displayed and it will wait for the player to press ENTER, upon which the screen will be cleared again and page 2 of the instructions will be displayed. On this page, the player will see a diagram of which keys are to be used for controlling the > symbol during gameplay. It also tells of how the game will slow down, and needs to be re-booted using the ENTER key while playing in order to get it back up to speed.

Program Code edit

Notes:

  1. Many of these lines of code can be linked together in one line by just typing a ":" instead of pressing ENTER and typing the next command on the next line. Also, some of the commands displayed here are already linked in this way.
  2. The "¤" found in the command, " :Text(8,69,"¤ ", is actually a very small square and it can be found in the CATALOG menu on your calculator. It will be above what looks like a small plus sign (+), near the bottom of the list.
PROGRAM:CSTART
:"CHASE STARTUP   SCREEN      <-- This line is unnecessary, but is a helpful note
:FnOff                              for anyone who opens the editing screen for CStart
:AxesOff
:ZStandard
:84→Xmin
:52→Ymin
:ZInteger
:Line(15,58,10,56
:Line(9,55,6,53
:Line(3,51,5,52
:Line(3,50,5,47
:Line(6,46,8,43
:Line(9,42,12,39
:Line(16,57,11,53
:Line(10,52,7,50
:Line(8,49,10,44
:Line(11,43,13,40
:Line(20,55,16,40
:Line(21,55,17,40
:Line(20,48,25,48
:Line(20,47,25,47
:Line(28,55,24,40
:Line(29,55,25,40
:Line(29,40,31,44
:Line(32,45,35,48
:Line(36,50,36,52
:Pt-On(33,47
:Line(39,56,42,38
:Line(39,55,42,38
:Line(34,46,40,46
:Line(34,45,40,45
:Line(55,52,54,52
:Line(55,53,49,53
:Line(53,54,51,54
:Line(50,52,47,51
:Line(48,52,47,50
:Line(46,50,46,47
:Line(47,47,48,46
:Pt-On(47,46
:Line(48,45,52,45
:Line(49,44,53,44
:Line(54,43,55,42
:Line(53,43,55,41
:Line(55,40,52,37
:Line(54,40,50,36
:Line(51,38,48,36
:Line(49,36,45,40
:Line(47,37,45,39
:Line(73,54,64,54
:Line(73,53,64,53
:Line(62,54,57,35
:Line(63,54,58,35
:Line(59,36,70,36
:Line(59,35,70,35
:Text(15,62,"≠
:Text(14,67,"≠
:Line(81,54,79,55
:Line(78,54,75,37
:Line(81,53,80,49
:Line(78,40,79,48
:Line(76,37,77,39
:Line(75,35,74,35
:Line(75,34,74,34
:Text(0,52,"HI SCORE:
:Text(0,87,[J](1,5
:If 100≤[J](1,5
:Text(0,83,[J](1,5
:If 1000≤[J](1,5
:Text(0,83,"!?!?!
:Line(0,18,1,20
:Line(1,21,3,23
:Line(4,23,6,21
:Line(7,21,18,26
:Pt-On(19,26
:Line(18,22,10,16
:Line(19,20,17,20
:Line(17,19,17,16
:Line(16,16,14,16
:Line(13,17,13,14
:Pt-On(9,15
:Line(12,14,18,14
:Line(7,13,11,12
:Line(8,12,14,3
:Line(11,11,11,9
:Line(12,9,13,9
:Line(13,8,13,6
:Line(14,6,16,6
:Pt-On(15,2
:Line(16,5,16,1
:Line(15,0,13,0
:Pt-On(12,1
:Line(11,2,1,10
:Pt-On(0,11
:Pt-On(3,22
:Line(3,21,4,21
:Line(3,20,5,20
:Line(3,19,6,19
:Line(20,17,20,14
:Line(20,7,20,4
:Line(21,17,21,12
:Line(21,9,21,4
:Line(22,13,22,8
:Line(23,11,24,11
:Line(23,10,24,10
:Line(25,13,25,8
:Line(26,17,26,12
:Line(26,9,26,4
:Line(27,17,27,14
:Line(27,7,27,4
:Line(23,15,25,16
:Line(23,18,23,19
:Line(26,19,26,20
:Line(22,20,23,21
:Line(25,21,26,22
:Text(42,39,"(PRESS ENTER)
:Pause
:Text(39,37,"1
:Text(39,40,") NEW GAME
:Text(45,37,"2
:Text(45,75," "               <-- These end-quote marks are unnecessary but there must
:Text(42,76,"         "       <---- be this many spaces before the end of the command.
:Text(45,40,") Continue             (There must be 1 space after "Text(45,75"
:Text(51,37,"3                       and 9 spaces after "Text(42,76", but no
:Text(51,40,") Instructions          close-quote mark is needed in either case.)
:Text(57,37,"4
:Text(57,40,") Quit
:While 1
:getKey
:If Ans=92
:Return
:If Ans=93
:Return
:If Ans=94
:Goto 9
:If Ans=82
:Then
:Output(8,1,"
:Stop:End
:End
:Lbl 9
:StorePic 0
:ClrDraw
:Text(0,24,"INSTRUCTIONS
:Text(7,3,"Welcome to Chase!  In Chase
:Text(8,91,",
:Text(14,5,"You are a hungry  >  symbol
:Text(21,2,"who's always on the lookout
:Text(28,10,"for a tasty  X  to eat.  But
:Text(35,6,"watch out for the  ≠  signs!
:Text(42,4,"They are vicious and would
:Text(49,5,"love to have you for lunch.
:Text(56,11,"Avoid them at all costs.
:Pause 
:ClrDraw
:Text(6,3,"Use the number
:Text(12,5,"keys to move:
:Text(8,69,"¤
:Text(18,62,"1   2   3
:Text(9,62,"4
:Text(9,76,"6
:Text(0,62,"7   8   9
:Line(70,53,70,55
:Line(73,53,75,55
:Line(73,50,74,50
:Line(73,47,75,45
:Line(70,47,70,45
:Line(67,47,65,45
:Line(67,50,66,50
:Line(67,53,65,55
:Text(27,10,"Press ENTER to pause or
:Text(33,1,"'Save' your game.  To restore
:Text(39,3,"the speed when Chase slows
:Text(45,3,"down    press ENTER twice:  it
:Text(51,9,"will save your game and
:Text(46,20,",
:Text(57,6,"then resume at full speed.
:Pause
:ClrDraw
:RecallPic 0
:End


GuessMe

Program Description edit

GuessMe is a wonderful, enjoyable game based upon the simple concept of guessing a number. In this game, the player interacts with the calculator in a sort of dialogue. When the program is initiated, a Main Menu opens and the player is given five options:

  1. 1,000
  2. 10,000
  3. 100,000
  4. HI SCORES
  5. QUIT

Option 4 types up a screen which displays the current high score for each of the three difficulty levels, and Option 5 simply quits the program and returns to the main calculator entry screen. If the player selects Option 1, 2, or 3, the game will begin. The game begins by the calculator choosing a random number for the player to guess. If the player chose Option 1, then the number chosen by the calculator will be any number from 1 to 1000. The maximum number for Option 2 is 10000 and the maximum number for option 3 is 100000. This means that there are three difficulty levels that the player can choose from and that the calculator will save a separate high score for each difficulty which can all be seen on the High Score page by selecting Option 4 from the Main Menu. After selecting a number for the player to guess, the calculator tells the player what is going on and prompts him for his first guess. It does so with these messages: "Im thinking of a number between 1 and 1,000..." (This will say "10,000" in difficulty 2 and "100,000" in difficulty 3), "What is it?" The player can then enter his first guess.

After each guess, the calculator will respond with a message saying "Higher" if the player's guess was too low or "Lower" if the player's guess was too high. In difficulty 3, the calculator may also say "Much higher" or "Much lower".
If the player guesses a number which is less than 1 or more than the maximum, the calculator will respond with, "Hey! I said it was between 1 and 1,000!" (As before, this final number will depend on which Option was chosen).
If the player's guess is within 1 number of the answer then the calculator will say "Youre SO close! Just a little higher!" or "Youre SO close! Just a little lower!"
After 20 guesses, the calculator will taunt the player with the message, "Hurry it up!"
After 30 guesses, the calculator says "Gosh! You take forever!!!"
The only other message that the calculator might show to the player is one that will only be displayed if the player cheats to guess the answer on his first try or if by chance he guesses the secret number on his very first try. If this is done, the calculator will simply say, "YOU CHEATER!" and the program will abruptly end.

When the player eventually guesses the correct number, a series of messages will be displayed. The first is: "You got it!!!", followed by the correct answer, then "In this many tries:", followed by the number of guesses it took the player to find the number. Then, if the player has broken the high score for that difficulty level, he will see the message, "HIGH SCORE!!"

Note: The variables used by the calculator to operate GuessMe are stored in the [J] matrix.

Program Code edit

PROGRAM:GUESSME
:ClrHome
:{3,9}→dim([J])
:0→X
:If 0=[J](3,7)
:Then
:100→[J](1,8)
:100→[J](2,8)
:100→[J](3,8)
:End
:Lbl 6
:Menu("MAIN MENU","1,000",1,"10,000",2,"100,000",3,"HI SCORES",5,"QUIT",Z)
:Lbl 5
:Output(2,3,"HI     1:     SCORES:  2:)
:Output(4,10,"3:)
:Output(2,13,[J](1,8)
:Output(3,13,[J](2,8)
:Output(4,13,[J](3,8)
:Output(7,3,"PRESS ENTER")
:Pause 
:ClrHome
:Goto 6
:Lbl 1
:1000→C
:Goto 4
:Lbl 2
:10000→C
:Goto 4
:Lbl 3
:100000→C
:Lbl 4
:randInt(1,C)→B
:ClrHome
:Disp "Im thinking of a","number between 1","and"
:If 3=log(C)
:Output(3,5,"1,000...")
:If 4=log(C)
:Output(3,5,"10,000...")
:If 5=log(C)
:Output(3,5,"100,000...")
:Lbl A
:Input "What is it",A
:X+1→X
:If X=20
:Disp "  Hurry it up!
:If X=30
:Disp " Gosh! You take","   forever!!!"
:If A<1 or A>C
:Then
:Disp " Hey! I said it"," was between 1"," and"
:If 3=log(C)
:Output(7,6,"1,000!")
:If 4=log(C)
:Output(7,6,"10,000!")
:If 5=log(C)
:Output(7,6,"100,000!")
:Goto A
:End
:If A<B-1 and A>B-25000
:Then
:Disp " Higher"
:Goto A
:End
:If A>B+1 and A<B+25000
:Then
:Disp " Lower"
:Goto A
:End
:If A≥B-1 and A<B
:Then
:Disp " Youre SO close!"," Just a little","    higher!"
:Goto A
:End
:If A≤B+1 and A>B
:Then
:Disp " Youre SO close!"," Just a little","     lower!"
:Goto A
:End
:If A≤B-25000
:Then
:Disp " Much higher"
:Goto A
:End
:If A≥B+25000
:Then
:Disp " Much lower"
:Goto A
:End
:If A=B and X=1
:Then
:Disp "  YOU CHEATER!"
:Output(1,1,"")
:Stop
:Else
:Disp "  You got it!!!",B,"","In this many","     tries:",X
:Output(2,1,"")
:End
:If X<[J](log(C)-2,8)
:Then
:X→[J](log(C)-2,8)
:Output(8,3,"HIGH SCORE!!")
:1→[J](3,7)
:Lbl Z
:Output(1,1,"")
:Stop