Advanced BASIC for the TI-83

By: Wade Peterson

Logic Statements
Save Feature
Graph Menus
Revising Code

I. Logic Statements

(I will be using /=/ for a not equal sign) First of all, logic statements are things such as X=1 or Y>0. You should know that 0 means the statement is false and any other number means it's true. For example, X=1 would return a 1 if X equals 1, and 0 if X equals anything else.

Let's say you want to have a program do something when X does not equal 0. You could do this:
:If X/=/0
A better way of doing it is just:
:If X
It's the same because it checks if X is true (not equal to zero).If you wanted to do something when X equals zero just put:
:If not(X
This checks if X is false (zero)

Another shortcut is not using If statements when all you're doing is changing a variable:

:If K=26

A better way of writing this would be:


This is the same because if K=26, then (K=26) will equal 1 (true), so it will add 1 to X. If it's false it will add 0 to X, not changing it. So instead of:

:If K=34

You would put:


This multiplies 2 by (K=34). If K=34, it adds 2*1=2 to X, if K/=/34 it adds 2*0=0 to X.

II. GetKey

You may have made a game and used a getkey statement like this:

:If K=26
:If K=24

However this takes up a lot of space, and is slow. A better way of doing it would be:


By using the technique above you can change 4 lines into one. It's shorter and it runs much faster.

There is a way faster than that above, but it only works if you are manipulating one variable. By using Ans you can make the above run faster. Ans is very strange, however, and is easily erased. It gets overwritten each time you store something to a variable. Here's how you would do the above using Ans:


What happens is when the program comes across the GetKey statement, GetKey gets stored to Ans. So on the next line Ans is equal to GetKey. However, after this line, X gets stored to Ans, so Ans will no longer be equal to Getkey, so you can't use Ans again. So if you need to manipulate two variables, like when changing the x and y coordinates of an object, it's best just to store getkey to a variable.

III. Save Feature

Have you ever made an RPG or some other long game, and wanted to add a save feature? Even if you know how to, here's are three real good ways to do it:

1) If all you need to save are variables like A-Z, then do this:


2) If you need to save several lists do this:


3) If you need to save lists AND variables do this:


The first one simply stores the variables to a list. The second one uses augment to combine the lists together, and then store them to the list. The third way is to use both steps and combine the lists with the list of variables.

Now, once you have the game saved, you need a way to load this saved game. At the very beginning of your program you need to do this:


What this does is sets up the save list. Replace X with the dimension (length) of the list. Now I'll give a very basic example of a menu with the continue function:

:Menu("NEW GAME",N)

This is a very basic way of making a menu, but it demonstrates how the dim() feature works. By storing the dimension of the list before you load it, then if the list does not exist, it creates it and fills it with zeros. So the If LSAVE(1) checks if the first item in the list is not zero, and if so then adds the Continue feature to the menu.

Now for the actual loading part. If you're just loading variables it's a bit hard. You'd have to do something like this:


However, if you saved by storing a list to the save list, it's very easy. Just put:


And if you saved several lists with the same dimensions to the save list, do something like:


So when making an RPG only store frequently used values such as HP, MP, money, etc. to variables, and store most of the other things (items, etc.) to lists.

IV. Graph Menus

First before I go into the menus I'll talk about the 2nd key. You've probably noticed that 2nd button is much easier to press than the Enter button. So in your programs, instead of putting Pauses put:

:Repeat getKey=21

This way the program doesn't continue until you press 2nd. However, to save space, you should make this a subprogram. Create a new program and name it something one letter long like prgmZ. This way, every time you would normally put Pause, you can put prgmZ

Now what does this have to do with menus? Well in the menus built into the 83, to select something you must press Enter. Also those menus don't look to great, and you can't fit too much onto one line. The solution to all these problems is to make a menu on the graph screen.

You will want to make a subprogram named something like prgmM. Then inside the program type:

:If W>1
:If W>2
:If W>3
:If W>4
:If W>5
:If W>6
:If W>7
:Repeat K=21
:Repeat K
:Text(6V-6+Z,X,"   "
:If V<1
:If V>W

First, before you execute this program you'll need to change some variables. Store how many items are in the list (1-8) to W. Now store the first item to Str1, the second to Str2, and so on. Now store the horizontal position of the menu to X. Store the vertical position of the first item to Z. Then add in prgmM. Here's an example:

:"NEW GAME->Str1

This will display a menu with all the items 30 pixels from the left, and the first item 10 pixels down from the top. Something like:

           >NEW GAME


There are many different types of errors you can receive in a program, but the worst, by far is ERR:MEMORY. There is no way to really "fix" this error, except to erase parts of your program. However there are several steps to take to avoid this error. One is to revise your code. There are other ways to prevent it with out cutting out parts of your program.

For example, have you ever played a long RPG, and the more you played, the slower it got, until finally you got an ERR:MEMORY? This is because the program keeps running, and doesn't get a chance to stop. One way to solve this is by inserting breaks in your program. For example every time you save your game, the program can stop. However if it just stops, there is obviously a problem. To insert a stop into your program without the user realizing it, do this:

--rest of the program--
:Output(4,4,"Press ENTER

In the save program, after the saving part, enter the above code. The 1468 can be replaced by any strange number. Now when the user presses Enter, it executes the main program. So in the beginning of the main program put:

:If X=1468
:Delvar X
:Goto ?
:Delvar X

So after you save and press enter, it starts up this program. Since the last thing you did was save, x equals 1468, so then the program jumps to where ever you left off. The ? in Goto ? is the label where the program left off.

VI. Revising Code

There are many ways to revise code. Lots of things you type are unnecessary. Here is a list of things that can be omitted from your programs:

Take out end parenthesis:


Take out end quotes:

   Disp "ABC"
   Disp "ABC

And never use the * sign:


1999 Wade Peterson