TI-83 BASIC Used in Programming Games
By Anonymous
This teaches readers how to program games in TI-83 basic.

Programming in TI-83 BASIC:

There are a few basic commands that you need to know to use TI basic to make good games. First of all, there are two commands that make text appear on the home screen (normal place where cursor is, not the graph screen). The first way is the easiest. It is Disp (Display). An example would be this:

Disp "HELLO"

There is, however one thing that can be improved upon in this line: the end quotation mark doesn’t have to be there…in general, if an end parenthesis or quotation mark isn’t put in, it is just assumed that it is at the end of the line. In this way, you can save lots of memory. This will work with almost all commands, you’ll just have to experiment until you have it down which work and which don’t.

You may be asking what do I do if what I want to say takes up more than one line? Well this is how you would do it…

Disp "THIS TEXT TAKES","UP MORE THAN ONE","LINE

What has been done here is after every 16 characters (that’s how long across the screen is) a sequence "," has been added. This tells the calculator to go onto the next line.

Another note about the Disp command is that the text is displayed in the next blank line…if there is writing on the first, it starts on the second, etc. If there is writing on the last line of the screen, it will make the screen scroll up until the end of the command is viewed.

That is about all that needs to be known for the Disp command. Another command that serves a similar purpose is the Output command. Here is an example:

Output(1,4,"TEXT GOES HERE

This will display ‘TEXT GOES HERE’ in the first row, fourth column. With this command, there is no way to tell the calculator to go onto the next line, so you have to put spaces until the place where you want the next few words to go is reached.

There are some other commands that are useful when dealing with the home screen. The first is ClrHome; it clears the screen. This should be used at the beginning of any program because any left over text from previous work or games won’t be seen. If you don’t want your Disp commands to make the screen scroll up, you should use a ClrHome and a Pause between them (I will explain pause next).

The next important command is Pause. It is used when a programmer wants to stop the program until a person presses the enter key (helpful after text so they have time to read it).

These commands have all had to do with the home screen. The other type of screen is the graph screen. It is the place where any graphs are shown and pictures are drawn. Here are some basic commands on the graph screen:

Text( makes text appear on the graph screen (what a surprise) It is a little more complicated than Disp, but very similar to Output(. Here is an example:

Text(10,20,"THIS IS ON THE GRAPH SCREEN!

This will write THIS IS ON THE GRAPH SCREEN! on the graph screen 10 pixels down and 20 pixels across. Notice that this doesn’t have to be under 16 characters because the text on the graph screen is much smaller.

Another important command for the graph screen is like ClrHome…it is ClrDraw. ClrDraw clears the graph screen, although any functions will still be graphed after the screen is cleared.

The commands, AxesOff, FnOff and ZStandard are helpful because they turn off the axes, turn off the graphing of functions, and make the window –10<10 and –10<10, respectively. All of these can interfere with pictures, and are recommended…they may already be set that way on your calculator, but other calculators may not be this way.

Xmin, Xmax, Ymin, and Ymax are variables that can be set to change the dimensions of the screen. This can be helpful when programming some graphical games.

Line( and Circle( are two other important commands for drawing a picture. Here is an example of Line(:

Line(1,1,1,10

This will draw a line from the coordinate (1,1) to the coordinate (1,10).

If you want to erase a line, you just a ',0' to the end, so to erase the previous line, you would write this:

Line(1,1,1,10,0 

Note that lines use graph coordinates, not pixel coordinates.

Circle( is another important graph screen command. First you write the X coordinate, then the Y, then the radius…an example is this:

Circle(0,0,10 

This will draw a circle with radius 10 and center (0,0).

On the graph screen, there are 62 pixels (up and down) and 94 pixels (side to side). To use these pixels, there are many commands.

The first are Pxl-On( and Pxl-Off(. These two commands turn on/off a pixel using Y,X format. This is how the Pxl-On/Off is used:

Pxl-On(1,10 

This will put on the pixel in the 1st row, 10th column.

Pt-On and Pt-Off work in the same way. However, instead of putting on specific pixels, they put on/off a certain point of the graph. If I wanted a dot to be in the middle of the graph screen, this is the program that I would run to make it happen:

ClrDraw 		(to clear the screen) 
AxesOff 			(to make sure all that is visible is the point) 
FnOff 				(so no lines are drawn on the screen) 
Zstandard 			(to set (0,0) to the middle) 
Pt-On(0,0 

Note that in Pt-On/Off, you have to put the X coordinate first.

One final important command for the graph screen is Pxl-Test(. This command tests if a pixel is on or off (important for a few games that I can think of). If it is equal to 1, the pixel is on, otherwise it is off. Here is an example:

Pxl-Test(1,10) 

This will be equal to 1 if the pixel in the first row, tenth column is on. Otherwise, it will be 0. This can be used with an If statement…that is the most practical use. (If statements will be discussed a little bit below) Note: there is no Pt-test, so be careful in deciding to use pixels or points!

The final few commands are StorePic and RecallPic. From these, you can save the screen as a picture and recall it any time, and you use RecallPic to recall that picture. Here is an example:

StorePic Pic1 
ClrDraw 
RecallPic Pic1 

This program will save the screen as Pic1 and clear it. It will then recall pic1 (restore the screen to what it was before the ClrDraw)

Be careful because other programs can interfere with a picture you have saved. It is best to create the picture in the program once and then save it and use it throughout the program instead of creating the picture out of the program and saving it from the home screen.

The next part of this guide is dedicated to the commands that can be used on any screen or the ones that are unrelated.

The most important command in this group (imho) is if-then statements. If you have done any programming before, you probably know what I'm talking about, but if not, read on, you will understand.

There are four different commands used (or that can be used) in if-then statements. These commands are If, Then, End, and Else.

Her is an example of an If-Then statement.

If X=10 
Then 
Goto A (explained later) 
Else 
Goto B 
End 
Lbl A (explained later) 
Disp "X=10 
Stop (Ends program) 
Lbl B 
Disp "X[is not equal to]10

This may seem like it is a rather complicated program, but really it isn't. It basically asks the calculator whether X=10 and if so it displays that x=10 and if it is not, it displays that x is not equal to 10. This is kind of poorly explained :( but I will continue giving examples when I explain the different rules/non-rules of if-then statements.

First of all, these statements don't need to include an Else in them. The statement could be this:

If X=10 
Then 
Disp "X=10 
End 

Else isn't needed in many cases, and can even be a hassle.

Another thing that you need to know is that if there is only one line after the If statement, a Then isn't needed and an end isn't needed. For example:

If X=10 
Disp "X=10

This program will do the same as the one above, but it takes up much less memory. Basically, if there is no Then after the If, the calculator assumes only the next line applies to the If statement and then moves on.

Logic statements are often used with If, Then, and End. For example, if you want something to happen if only two conditions are correct, you would use an "and". If you want something to happen if one condition is correct, OR another is correct, you would use the "or" command. Here is an example of each:

If A=10 and B=10 
Disp "A AND B EQUAL 10 
If A=10 or B=10 
Disp "EITHER A OR B","EQUALS 10

Another important command is the all-important getkey. Basically, getkey works like this: each key on the calculator (except the on key) has a key code that can be used with the getkey statement. Getkey tests for what key is pressed, and based on that, you can do certain things if a certain key is pressed. This is an example of how getkey works:

Getkey->K 
If K=24 
A-1->A 
If K=26 
A+1->A 
If K=25 
B+1->B 
If K=34 
B-1->B

This will add/subtract 1 from A or B depending on which arrow key is pressed. There is a guide to all the getkey equivalents in the TI-83 book.

This program can be simplified to save memory (in two ways) however, for now its best to just learn how to use each command, then how to simplify later…

Goto and Lbl are a way of skipping over part of a program. If you want to go to a specific point, you create a Lbl such as Lbl A and then where you want it to jump to that place, you would put Goto A. For example:

Goto A 
A+1->A 
Lbl A 

The command line, A+1->A would not be executed because the program would jump from Goto A to Lbl A. Note that this can be used over longer distances as well.

It's been long enough…its time to learn one of the most important concepts in programming: loops. There are three main kinds of loops in TI basic, those are For(, Repeat, and While. Remember, EVERY loop needs an end to signify the end of the loop! This can mess up a program completely if you don't have an end.

I will start by just give examples of all three. Here's an example of a For( loop:

For(A,1,7 
Disp A 
End 

This will make A increment from 1 to 7 and show what it is at the time on the home screen. In general, For( loops in the form, For(A,B,C,D

Makes A equal from B to C at increments of D (if D isn't included, increment is 1)

Here is a Repeat loop:

Repeat A=10 
A+1->A 
End 

This will run until A is equal to ten (the line of code can be read repeat UNTIL A=10). A repeat loop must be cycled through once, if you don't want this to happen, use a while loop.

While loops work like this:

While A<10 
A+1->A 
End 

This loop goes through the line, A+1->A if and only if A is less than 10. If it is greater than 10, the program skips over this.

The fastest loop is the For( loop. This should not, however, be the only way you decide what loop to use. In general, a For( loop should be used when you have to do the same thing, only changing the numbers involved. For example, if you had to draw lines on the screen at a designated height across the screen, you might use this program.

For(Z,0,94 
Line(Z,1,Z,30 
End 

While statements should be used if you only want the loop to be executed if a certain if-then statement is true. If you want a program to go through the loop at least once, use repeat. I'm not 100% sure of this, but I think that repeat is the slowest of the loops.

Another important section is random numbers. These can be very useful in a gambling game where the numbers have to be random. A random number is created this way:

Int(Arand+B->C 

In this line, A stands for the number of choices you want, B stands for the minimum number you want, and C is the variable that the random number is stored into. For example:

Int(10rand+1->A 

Will store a random number between one and ten into the variable A.

Well, that’s about all the important stuff for making good games, or at least what I can think of now. All this information is a lot to handle, especially all at once. If you have any problems/corrections contact me at bennyf118@hotmail.com and I will try to solve any problems you might have. However, be warned that if you ask me every time to solve a problem, you won't learn much, and your time will be wasted (in a way). Anyway, I'm done rambling, happy programming :).