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 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 programs. If the last command that alters the screen (e.g., Disp, ClrHome, etc.) is Output(, then
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
Done, just put an empty string at the end of your program.
Note that boolean values are represented by
1 is true and
0 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.
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:
A=1, it deletes
A and then produces a Syntax error, because End is encountered twice. If
A=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.
Movement with getKeyEdit
Changing the X and Y variables with key presses could be done with four If commands:
This is a better way to do it:
If you can, don't place values in variables, 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.
You can end a For( loop prematurely by setting the variable it iterates to the end value:
You can have these kind of constructions:
These can save a lot of space in some situations.