TI-Basic Z80 Programming/Advanced Programming

This section will focus on advanced programming techniques which will help you manage your code better and create advanced coding structures.

Idioms
Idioms are pieces of code that are used repeatedly from program to program.

Invisible "Done"
the following code will clear the screen and get rid of the  that follows programs. If the last command that alters the screen (e.g., Disp, ClrHome, etc.) is Output(, then  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, just put an empty string at the end of your program.

Booleans
Note that boolean values are represented by  and   where   is true and   is false. This makes integrating true/false conditionals into equations very convenient.

Never use = tests for boolean values. Instead you can use:

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.

Use DelVar
The power of DelVar often goes unrecognized. The following are all legal code using DelVar:

As you can see, DelVar is a very efficient way to delete variables, as it can also run another command on the same line.

Despite this, there is a catch:

If, it deletes   and then produces a Syntax error, because <tt>End</tt> is encountered twice. If, nothing happens and the program exits normally because the <tt>End</tt> after   is ignored. This is a design flaw in the TI-Basic interpreter.

Scrollable Lists
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.

Pause
On the subject of pause, you can pause on variables, strings, and text, which is convenient.

Movement with <tt>getKey</tt>
Changing the <tt>X</tt> and <tt>Y</tt> variables with key presses could be done with four <tt>If</tt> commands:

This is a better way to do it:

<tt>Ans</tt>
If you can, don't place values in variables, but store them in <tt>Ans</tt>. <tt>Ans</tt> 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, <tt>Ans</tt> is set to that value.

<tt>For(</tt> trick
You can end a <tt>For(</tt> loop prematurely by setting the variable it iterates to the end value:

<tt>If</tt> trick
You can have these kind of constructions:

These can save a lot of space in some situations.