Lesson 3

Variables, Strings, Lists and Matrices

In this lesson, we shall be going over some of the uses of variables, strings, lists and matrices, but we will not be able to get into heavy detail until we manage to get into more advanced levels of this series of tutorials.

Variables:

Simply put, variables is a form of data storage, that stores numerical values, and can be used in many mathematical situations. Below is a pic of how you can properly store to a variable:

Click for animated screenshot

Variables tie into the other above mentioned variables, and we will get to them in due time. There is not really a whole lot to learn about variables of this sort, other than displaying a variable's value is as simple as Output(1,1,A , Disp A , and Pause A and that it can be used mathematically. You can use variables A-Z and θ.

Another set of variables that you can use are located in the Finance App by pressing the [APPS] button. Select the finance app and press right to access the VARS submenu. This will give you 7 more variables to use, but be warned: these variables take up 2 bytes instead of 1, but do not show up in the memory menu.

Lists:

Lists can be considered the back bone to many games, saving highscores, or saving progress in an RPG. The reason for this is you can create a list to have 999 slots to save information to, memory allowing. A nice feature to lists are that they do not change in size when you add values to the list elements. A 999 defined list will take 9003 bytes of memory. There are 6 predefined lists, that are readily accessible by pressing [2nd] and [1]-[6]. The 83+ has the nice feature of allowing the user or program to create a user defined list, to keep other programs from accessing and corrupting the data needing to be saved. You can do this by accessing the List menu. Press [2nd] and [STAT]. You should be looking upon the following screen:

what it looks like

The first submenu is a list of lists that are currently stored onto the calc. If the calc is brand new, or you have reset the memory, L1 through L6 should be displayed in this list. The second submenu contains commands neccessary to create lists, define the length of lists, and even organize list elements. The third submenu is for using lists in mathematical equations. For now, I will explain how to create and use lists.

There are different ways to set up lists. You can simply store to a list by typing {1,2,3,4,5,6,7→L1 on either the homescreen or inside a program. Please note that if the list already exists, it will be overwritten, unless it is in the Archive, then it will return an ERR: ARCHIVED. Once you set it up like this, you can only pull from those list elements. If you wish to increase the number of elements within the list, or to preset the number of elements, use the dim( command.

The dim( command will create a list by defining the amount of elements that are available. A nice feature to the dim( command is that it does not overwrite the data within the list elements. To use this command, simply type #dim(L1 where # is the number of elements you want the list to have. You can use the mentioned code either on the homescreen, or within a program, it will work just the same. Now, the only draw back to the dim( command is that if the list exists, and is archived, it will return an error.

Click for Animated screenshot

As you can see from the animated screenshot, that will post a problem when someone is trying to play a game. So, to make it so you can create lists without getting the ERR: ARCHIVED "crash" is to use the SetUpEditor command. This command is great, as it will do different things. First, it checks to see if the list name exists. If it does not exist, it creates the list, with 0 list elements. If it does exist, then it checks to see if it is in RAM or Archive, and if it is in the Archive memory, it unarchives it. This command is excellent, when combined with the dim( command to check if save data exists. This is the code to achieve this:

:SetUpEditor LABC
:dim(LABC
:If Ans=0		;Ans will be discussed in more detail at the end of this lesson.
:Disp "LIST NOT DEFINED		;If will be discussed in the next lesson.
:If Ans>0
:Disp "LIST DEFINED

This is what you should get/see on your calculator: animated screenshot

Now, that is not being overly specific. It is just checking to see if the list has any elements to it, which would normally mean it has been used. To make a better save data checker, you would need to check the data within the list elements are also something other than 0. To check what is in the third element, you would need to use the following: LABC(3. You also store values in this way, by doing this: 20LABC(3. This is what you should get when entering all that in: animated screenshot

Another command that you should familiarize yourself with would be the Fill( command. What this command does is it fills a list with a specified value. The format is this: :Fill(14,LABC
You should see this: animated screenshot

That finishes off the basics of using lists. As we move on to other lessons, we will delve into some of the other commands in the list menu.

Matrices:

Matrices are great for many things, one being a level or map storage, another is for stats. The only problem with matrices are that they consume alot of memory very quickly. Matrices can be found by pressing [2nd] and [X-1]. There you will find a list of available matrices, ranging from [A]-[J]. To set up a matrix, you need to start with a bracket. This signifies the start of the entire matrix. Place another bracket after that to start the first row. You should have something like this now: [[.

Now that we have started a matrix, we need to know how big we want it. For beginners sake, we will stick with a 3x3. Numbers in a matrix are seperated by commas, and if you have very large matrices, this can cause you to overlook an error, due to trying to look at all of the numbers. But don't worry, the 83+ is kind enough to display an error, and give you the option of quitting, or going to where the error occurred. Anyways, we shall set up the matrix as follows:

[[1,2,3][4,5,6][7,8,9]][A]

Now if you select matrix [A] it will display the following screen:

Recalling from a marix is easy. The syntax to check a certain point in the matrix is:

[A](A,B

Accessing A will give you access to the rows inside the matrix. Accessing B will give you access to the columns within the matrix. Storing to a matrix is the same as you would store to a list, albiet with more numbers. Recalling and storing to a matrix

You can also use the dim( command to create a matrix. To do so, you must use the following format: {3,3dim([A] Using dim( in a matrix

And using this, like the lists, will not overwrite data that already exists. Another command you can use with matrices that you are already familiar with is the Fill( command. It has the same syntax as using with a list:

I know you are curious on how we can use a matrix for a level or map, but the problem is is that we haven't learned all the commands neccessary to do that yet. Mainly, we need boolean logic that is discussed in the next lesson.

Strings

Strings are variables that store text, which include numbers. Strings, in the normal sense of variables, cannot be used (easily) to do mathematical equations. Creating these variables are easy, and they can be as long as there is memory (most letters/numbers take 1 bytes, most commands take 1 byte, though smaller letters (accessed through an asm program or shell (Doors CS and Mirage OS)) take 2 bytes.

To set up a string, start with " and begin typing out what you want. The only command that I am aware of that DOES NOT work in a string is the Sto () character. It is possible to get it into a string, though that will be discussed in another lesson.

To store to a string, you need to use one of the string variables. They can be found in the VARS section, found by pressing [VARS]. In this menu, you want the 7th menu option, String.... This gives you a list of 10 string variables that you can use, Str1-Str0.

Store to Str1 like this: "HELLO WORLD!Str1

There are some commands that deal strictly with strings; sub(, InString(, and Length(. The easiest command is Length(, and will be the first to be discussed.

The Length( command returns the amount of characters in a string or string variable. You can store the value to a variable, or let Ans hold on to the value for a short time. The command syntax is extremely easy to understand. You can use the following syntaxes: Length(Str1       Length("ABCDEFG"    

The sub( command allows you to access parts of a string. The syntax for the command is sub(Str1,start of string,length of string. What this means is that you tell the sub( command what string to pull from, where in the string to start at, and how many characters to go, to the right of the starting point. You can also take a part of a string, and store to another string. The sub( command can also be used to check what character is in a certain part of a string. This will be covered in the hit detection lesson.

Here is a screenshot of sub( in action:

InString( is a nice command that checks to see if a character or string is stored within a string, and returns the position of where it first encounters it in the string. You can also use the optional character position to tell InString( where to start looking. The syntax for this command is this: InString(Str1,"O",6      

Another thing about strings is the ability to concatenate, or add, strings together. You can add strings either by storing them in string variables, and adding them together, or you can add a string to a string variable, like in this screenshot:

Ans

The Ans variable is the best one that TI thought to put on the calculator. The reason being is that it can be ANY of the varaibales discussed above. The only problem with the Ans variable is that anything that can be stored to a variable, either through an equation, or string, will update Ans. So Ans does not make for good data storage, but works very well for temporary data storage.

Command definitions for this lesson:

dim(: This command sets the dimension of a list or matrix, without overwriting data already stored in the list or matrix variable.

Fill(: This command fills a list or matrix with a value.

InString(: This command will look in a string, and compare to another string, and return where in the first string the second string shows up. Can also 
be set to start at a certain point in the first string.

L: This command allows you to create lists with curstom names.

length(: length( returns the number of characters in a string, can be stored to a variable.

SetUpEditor: This command will create a list variable, or unarchive it if it is archived. Very handy to keep from getting errors.

sub(: sub( can be used to access a certain character or characters within a string.

These commands are very important for making a good game, whether it is an RPG, or other type, because if you didn't have these things, manipulation of data would be impossible.

<<Previous - Contents - Next>>