"Advanced TI-82 Programming Techniques"

With your host Frank Force.

Hi, this is a new column directed to ti-82 programmers. It's very important not to disregard this column because you think you're too good. In fact, I'm writing this especially for experts. I see many games out for the ti-82, but no one takes full advantage of what a ti-82 can do. The tricks I'm going to be talking about won't speed your program up dramatically, but it will definitely be noticeable. If you would like to see some of the games that I made, which take full advantage of these tricks, many are reviewed in this issue. Feel free to play around with them and check them out. If you have any comments, games, or tricks of your own, send them to me at *****@voicent.com.

LOGIC STATEMENTS

For a not equal to sign, I will be using !=; ! means not. In case you don't know what a logic statement is, it's the part that comes after ifs whiles and repeats, like X = 4. All of my examples will be using the if statement, but it can also be used with repeat & while. First off it's important to know that with ti-82 programming, 0 always means false and all other numbers always mean true. So 4 is true, -4 is true, and X is true as long as it does not equal 0. This brings us to our first trick. If you want an if to run only when a variable does not equal 0, X for instance, just put:

If X

Or if you want it to run only when X=0, put:

If not X

Not reverses the logic, 0 will turn into one, anything else will be 0. As you can see, this trick only works when a variable does not equal 0, but you can expand it for any != statement. How about X != 7?

If X - 7

Why is there a minus there? Because the statement will only be zero if X = 7. 7 - 7 = 0. But if X != 7, like if X = 5. 5 - 7 = -2, which is true. It also works for are last trick because X - 0 is just X! This trick doesn't work as well as the last one and is hardly noticeable, and sometimes slower then just !=. There are also ways to fix And & Or statements. And means *, or means +. Let's take a look at this.

If X = 1 and Y != 0
is the same as
If (X = 1)Y

You can probably see why Y != 0 translates to just Y, from the first trick. But for the and statement, I multiplied. To save program space don't include the *, if you did it would be If (X=1)*Y, but it's not necessary. Why does multiplying work? Because you only want And to work if they are both true, so if one or both are 0 (false), the whole statement would be 0 (false).

If X != 0 or Y = 5
is the same as
If X + (Y = 5)

As you can see the statement would work as long as either one is true (1). It would not work if they are both 0 (false). But be careful, you can run into problems with this trick. What if X = -1 and Y = 5. Then you can see that although both parts are true, it would not work because -1 + 1 = 0. Rarely will this happen to you though, but if so, just use the regular Or statement.

GETKEY

Here's a great way to use the Getkey command with the arrow keys and enter. It uses the Ans statement, so look out.

[Note: lines beginning with ; are comments]
Repeat Ans = 75.5/4.5
;Repeats until you press enter.
;(105 - 29.5)/4.5 = 75.5/4.5
Getkey - 25
;Stores in ans
If abs Ans = 1
;Left (24) or Right (26) - 25.
Then
;So now Left = -1 and Right = 1

;Run if you pressed Left of Right

Else
(Ans - 4.5)/4.5
;Up (25) or Down (34). Do the math.
If abs Ans = 1
;So now Up is -1 and Down is 1
Then

;Run if you pressed Up or down

End
End
End

Remember, Ans gets overwritten anytime you store a variable, but using it is much faster then storing Getkey to a variable.

One more thing I'd like to mention is the colon (:). As most of you know you can put it at the end of a statement to combine it with what would normally be the next line...

If X=5 : 0 -> X

But it should never ever be used! It takes up one byte of space each time, which can really add up. It doesn't do anything for the program's speed. And it makes the program hard to read. So don't use it.

On a final note, I should mention the benefits of ending programs with a return statement instead of a stop. Although this may not make your program better while standing alone, it will make it compatible with shell programs especially the upcoming Windows 82. Well, that's about it, next month we'll be doing Bypassing Ifs and More With the Ans Statement.