TI-Basic Z80 Programming/Advanced Programming
This section will focus on advanced programming techniques which will help you to more easily manage your code and create advanced coding structures. The code displayed here will work for certain on the TI-83 Plus and TI-84 series. I am not certain about the TI-83 standard edition though. This page is always under a revising process, never consider the information shown here to be complete.
Idioms are pieces of code that are used repeatedly from program to program.
the following code will clear the screen and get rid of the "Done" that follows Basic programs. If the last command that alters the screen (e.g.
ClrHome, etc.) is
Output(, then the "done" will not appear.
A different solution is to set a variable, string or a number at the last line. That value will be shown at the end of the program. So to remove the Done just put an empty string at the end of your program.
Note that boolean values are represented by 1 and 0 in TI-BASIC where 1 is true and 0 is false. This makes integrating True False conditionals into equations very convenient.
Note: Never use "=" tests for boolean values. Instead you can use the code
for "if true" and use
for "if not true". It may not seem like much, but in the end it will save you a lot of memory.
The power of DelVar often goes unrecognized. the following are all legal code using DelVar.
:Delvar ADelVar BDelvar C
:DelVar ADisp B
:Delvar ADelVar B5→C
As you can see, DelVar is a very efficient way to delete variables, as it can also run another command on the same line.
There is a catch:
:If A=1 :Then :DelVar AEnd :End
If A is 1, it deletes A and then produces a Syntax error, because an 'End' is encountered twice. If A is 0, nothing happens and the program exits normally because the End after DelVar A is ignored. This is a design flaw in the TI-Basic interpreter.
Scrollable lists can be quickly created by pausing on a list, for example,
However, its not the nicest looking layout, so only use it if you need to create a program really fast.
On the subject of pause, you can pause on variables, strings, and text, which is convenient.
:Pause A :Pause Str1 :Pause "My name is david becker"
Movement with getKey
Changing the X and Y variables with key presses could be done with 4 If commands:
:getKey→K :If K=24 :X-1→X :If K=26 :X+1→X :If K=25 :Y-1→Y :If K=34 :Y+1→Y
This is a better way to do it:
:getKey→K :X-(K=24)+(K=26)→X :Y-(K=25)+(K=34)→Y
If you can, don't place values in varables, but store them in Ans. Ans is a much faster way of storing values, and it won't overwrite any other data. The only bad thing is that if you store a value in variable, Ans is set to that value.
:10 :Disp Ans
You can end a 'For(' loop prematurely by setting the variable it iterates to the end value:
PROGRAM:PRIME :ClrHome :1→X :Disp 2 :Lbl A :X+2→X :1→A :For(Z,3,root(X)) "Here is the For( loop start :If not(fPart(X/Z)) :Then :0→A :root(X)→Z "This is where the variable is set :End :End "The loop will end here if Z is set to root(X), so the remaining dividers of X are not checked. :If A :Disp X :Goto A
root(variable) takes the square root of that variable, as I can't find the right sign for it.
You can have these kind of constructions:
:If ''condition 1'' :Then :''code executed if condition 1 is true'' :If ''condition 2'' :Else :''code executed if condition 1 is true or if condition 2 is true after the code block is executed'' :End
These can save a lot of space in some situations.