ok, arrays, to me they are confusing, but I understand them
. So, quoting DBP help:
Quote: "This command will create an array in which you can store your program data. You are able to create arrays with up to
five dimensions. Arrays are best visualized as a line of boxes. Within each of these boxes are even smaller boxes.
Contained within each of these smaller boxes are single items of data. To locate the data contained in one of these
boxes, you must indicate exactly which box you wish to read from or write to. Each box has what is called an index
number. Starting with the largest boxes, you provide an index number that takes you inside a box. You can then provide
another index number that chooses one of the smaller boxes within the larger box. Every time you enter a new box, you
are in fact indexing a new dimension in the array. Using this method of indexing the array elements, you can read and
write to any value within the array. You can store only one type of data per array. Data types include integer numbers,
real numbers and strings.
"
Arrays are used for storing information about things without having a seperate variable for all of them. So, instead of:
item1 = 50
item2 = 10
item3 = 25
print item1
print item2
print item3
suspend for key
you could do this:
dim item( 3 )
item( 1 ) = 50
item( 2 ) = 10
item( 3 ) = 25
print item( 1 )
print item( 2 )
print item( 3 )
suspend for key
Its just easier to keep track of
. Now, something I use often in programming is arrays with types. First of all, what is a type? I think of a type as your own custom variable. It's best used to store different data about an entity (object, character, etc.) in the game. For a simple example:
type characterInfo
number as integer
name as string
life as integer
endtype
your creating your type, "characterInfo", and indicating its name, number, and life within the type. So, if you wanted to use an array with the type, you could do this:
type characterInfo
number as integer
name as string
life as integer
endtype
dim characterInfo( 2 ) as characterInfo
It may seem complicated at first, but this is what your doing...First your making your "type" (like i said, think of it as your own custom variable, that holds more than one value), then from that type your creating an array, which will hold information about your characters. I created an array from the type that I have defined, which you will call up later. Its important that although I named the "characterInfo" after the "dim" and the type "characterInfo" the same thing, that isnt necessary, it just helps me keep track of which dim is with which type. I could have named the array "characterStats" or whatever else I wanted. So, whats the advantage to doing this? So you can easily keep track of and call up information. Oh, and I'm making 2 characters by making the number of "boxes" in the array 2. Here's an example of it all together:
type characterInfo
number as integer
name as string
life as integer
endtype
dim characterInfo( 2 ) as characterInfo
characterInfo( 1 ).number = 1
characterInfo( 1 ).name = "Bob"
characterInfo( 1 ).life = 100
characterInfo( 2 ).number = 2
characterInfo( 2 ).name = "Joe"
characterInfo( 2 ).life = 50
So, whats this doing? First, we made our type that stores the character info, then we made an array to store information about each of our characters, and then we defined that information just like we would variables. When I typed "characterInfo( 1 ).name = "Bob"", I was defining the first character's name (in this case, this could be used for anything, food, items, horses, whatever you want), and with the "characterInfo( 2 ).name" I was defining the second characters name. When recalling info from types, use a period to seperate each variable. So, I hope your following me. Oh, and in case your wondering why i used the "as" statements to define the type of my variables instead of a "#" or "$", its just because theres more than one way to do it, and really, using an "as" statement is the better way, so you dont have to constantly add a "$" or "#" to the end. So, for a last example pulling together everything about types, arrays, and variables, heres some code:
camspeed# = .01
nmrOfCharacters = 2
type threeDimensions
x as float
y as float
z as float
endtype
type characterInfo
number as integer
name as string
life as integer
position as threeDimensions
endtype
dim characterInfo( nmrOfCharacters ) as characterInfo
characterInfo( 1 ).number = 1
characterInfo( 1 ).name = "Bob"
characterInfo( 1 ).life = 100
characterInfo( 1 ).position.x = 10
characterInfo( 1 ).position.y = 2.5
characterInfo( 1 ).position.z = 10
characterInfo( 2 ).number = 2
characterInfo( 2 ).name = "Joe"
characterInfo( 2 ).life = 50
characterInfo( 2 ).position.x = -10
characterInfo( 2 ).position.y = 2.5
characterInfo( 2 ).position.z = 5
make object cube characterInfo( 1 ).number, 5
position object characterInfo( 1 ).number, characterInfo( 1 ).position.x, characterInfo( 1 ).position.y, characterInfo( 1 ).position.z
make object cube characterInfo( 2 ).number, 5
position object characterInfo( 2 ).number, characterInfo( 2 ).position.x, characterInfo( 2 ).position.y, characterInfo( 2 ).position.z
do
control camera using arrowkeys 0, camspeed#, .1
loop
What your doing is simply making characters (cubes) with the properties of each of the defined characters. Hope you understand
. Feel free to ask questions you have
.