HOME >> Tutorials >> Tutorial 2: Arrays -- The Amazing Data Structure
Tutorial 2
Arrays: The Amazing Data Structure

 Select Tutorial... 1. Advanced Game Design 2. Arrays: Data Structure 3. Nibbles: Lists 4. Nibbles: Hit Detection 5. Scroll Screen Left & Right 6. Advanced Graphics 7. Trig Func & Relevant Uses

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

Arrays:
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:
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).

Initializing:

 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: 4->dim(Ltemp This creates a string of numbers that look like this: {0,0,0,0} Note that the dim( command can be used both ways. On homescreen enter: dim(Ltemp)  4

 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: 4->dim(Linstall if Linstall(1)  //then other program is installedif not(Linstall(1)  //other program not installed delvar Linstall In the secondary program (one your checking to see if it is installed), just type: 4->dim(Linstall1->Linstall(1)

 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 varsIf not(Linstall(1):Then //this is first time they run prog //put setup code in here. //storepics here1->Linstall(1)  //dont forget to put this in the setupEnd

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.

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:

 {4,2}->dim([A] 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 oneThen[[4,4,4,4],[5,6,2,3],[4,5,6,7]]End However, it is unnecensary to use up that much space. You could rewrite it as follows: 3->dim(L1If L=1:Then4444->L1(1)5623->L1(2)4567->L1(3)End 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: 12->Aipart(A/10)->Cipart(10*fpart(A/10))->D After the above: C=1, and D=2. Using this same method you can create a decompression algorithm: {3,4}->dim([B]For(Y,1,3L1(Y)->ZFor(X,1,4ipart(10*fpart((Z/10^X)))->[B](Y,X)End:End

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:
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.