Advanced BASIC for the TI-83
By: Wade Peterson
(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:
A better way of doing it is just:
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:
This checks if X is false (zero)
Another shortcut is not using If statements when all you're doing is changing a variable:
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:
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.
You may have made a game and used a getkey statement like this:
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.
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.
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:
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::X->dim(LSAVE)
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::If LSAVE(1
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::LSAVE(1)->A
However, if you saved by storing a list to the save list, it's very easy. Just put::LSAVE->L1
And if you saved several lists with the same dimensions to the save list, do something like::For(X,1,6
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.
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:
:1->V :X-4->X :Text(Z,X,Str1 :If W>1 :Text(Z+6,X,Str2 :If W>2 :Text(Z+12,X,Str3 :If W>3 :Text(Z+18,X,Str4 :If W>4 :Text(Z+24,X,Str5 :If W>5 :Text(Z+30,X,Str6 :If W>6 :Text(Z+36,X,Str7 :If W>7 :Text(Z+42,X,Str8 :Repeat K=21 :Text(6V-6+Z,X,"> :Repeat K :getKey->K :End :Text(6V-6+Z,X," " :V+(K=34)-(K=25)->V :If V<1 :W->V :If V>W :1->V :End :ClrDraw
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::3->W
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 CONTINUE QUIT
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:PROGRAM:SAVE
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
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.
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: (X=2)->Y (X=2->Y and Pt-On(X,Y) Pt-On(X,Y Take out end quotes: Disp "ABC" Disp "ABC and Output(1,1,"ABC") Output(1,1,"ABC And never use the * sign: 6*X 6X
©1999 Wade Peterson