HOME >> Tutorials >> Tutorial 2: Arrays -- The Amazing Data Structure
Advanced Game Techniques Tutorials
Advanced BASIC
Tutorial 2
Arrays: The Amazing Data Structure

   Advanced BASIC Tutorials

Part 1: Introduction
First of all, your probably wondering what exactly advanced programming is. For our purposes, we can define advanced programming as the ability to use all the available facits of the TI-Basic to create quality and technicaly complex games. In order to do this you must understand how the calculator uses the commands on a very low level. To use TI-Basic to make quality games you have to know what your doing. Since ASM programming is very fast, you have to be able to program very intelligently to make quality games that will compete with them. The purpose of these tutorials is to explain several advanced programming techniques. By starting at game design and ending at 3-D programming. It explains mainly the theorys behind these techniques and not the exact syntax of things.

For these tutorials it is assumed that you already know how basic basically works. If you don't know the syntax and how to use things like 'If' statements or 'Lbl's' then you should go read the many other Basic Tutorials out there on the web.

Part 2: Intro to lists

Basically an array is just an arranged ment of numbers. This arrangement can be either 1-d,lists, or 2-d,matrixes. To store large amounts of information, arrays become almost a requirementin advanced programming. Lists are most useful storing a long string of related information. And matrixes are often used for hit detection in games. If the calcultor doesn't know where everything is in the game, then it cann't know if they hit each other.

Lists are the most verstile data type on the TI-83. Since advanced data types such as structs, used in C and C++, are not available, the next best thing has to be used. A list is just an array of numbers that can be accesed with the memory address. Dont get scared at the terminology, lists are very easy to use. But the best thing about a list, is that you can name a list anything you like. And the good part about this is that other programs will not use your special list. If you used charachters to store, say the highscore, then that information might get damaged. So lists, are the data type that make storing information inbetween executions of the program possible (ok, you can use other things, but this tutorial isnt about those other things).


Before you can use a list, you have to tell the calculator that the lists exist. When you do this, the calculator is setting aside memory for the list. Creating a list is very simple, if you want a list named temp, that has 4 positions then type in:
This creates a string of numbers that look like this:
Note that the dim( command can be used both ways.
On homescreen enter:

The most amazing thing about this, storing into the dim(, is that it does not destroy any data if the list has already been initialized. This means that you can check to see if someone has installed a program. In the main program just type:
if Linstall(1)  //then other program is installed
if not(Linstall(1)  //other program not installed
 delvar Linstall
In the secondary program (one your checking to see if it is installed), just type:

This creates many advanced features that your program can use. If you use this then you will probably need to have a reinstall or uninstall program. Using this same method, you can check to see if this is the first time that the person has run the program. If it is the first time then you can ask them questions to set up the program and store them in your install list. Just type in:
3->dim(Linstall  //or whatever length you need for all your vars
If not(Linstall(1):Then
 //this is first time they run prog
 //put setup code in here.
 //storepics here
1->Linstall(1)  //dont forget to put this in the setup

Using installation procedures will make your game look more complex and advanced. One big plus to this, is that you can make it create a pic, and then store it. This would save the time that it would take to redraw the pic, getting rid of unnecensary lag time during the game. Also,this would save the need to transfer the pic between calcs. And after you send the program to another calc, it will know that this is the first time it has run and redraw the pic, then store it.

Part 3: Advanced Matrix Operations

Initializing Matrixes:
Alot of people dont utilize matrixes because they think that they are to hard. But matrixes are just as easy using lists. One thing that is tricky about matrixes is that they are referenced by Y,X, as opposed to X,Y for Pt-On( and Line(. You simply initalize matrixes as you would a list:

This would create a grid that is 4 spaces tall, and 2 spaces wide.

Utilizing Matrixes:
The most common use for a matrix is to store the data of the game screen. Use it for hit detection. For instance, if you were making a minesweeper game. At the beginning of the game you would randomly store mines throughout the matrix. Then, for the game, you would have a cursor that the user moved around. When the user pushed a key, then you would check the matrix, and output the number to the screen.

List to Matrix Compression:

If L=1  //if level is level one
However, it is unnecensary to use up that much space. You could rewrite it as follows:
If L=1:Then
But, if you have this, you must have a decompression algorithm. Every one knows that if you have the number 12. You can seperate the components 1 and 2 into seperate numbers:
After the above: C=1, and D=2. Using this same method you can create a decompression algorithm:

While all this may seem like a waste just to compress a level, when you have more than 15 levels stored in a game, then every saved byte counts.

If you don't understand this stuff:
  1. Reread the tutorial.
  2. Reread it again (throughly, and experiment with the code)
  3. Then I can't write good tutorials, or
  4. You should rethink wanting to program Advanced BASIC

Next Tutorial: Nibbles Game: Lists.

Written by Brandon Green.

Tutorial is property of Brandon Green, © 2000. Do not use without permision. Algorithms are property of Brandon Green, e-mail for permision to use.

Problems with this page?
Contact the Webmaster.