###

» Sun Feb 15, 2015 4:21 am

You can see arrays as a collection of lists, depending on the amount of dimensions there are in it.

For instant a 1 dimensional array is just like a list or if you imagine making 5 variables named:

X0, X1, X2, X3, X4

So instead of referring to each variables name like:

Set X0 = A

Set X1 = B

etc.

You can use an array, which have an index number instead, so imagine you have an array called X:

X: [0],[1],[2],[3],[4]

Then you could assign values like so:

Set X[0] = A

Set X[1] = B

etc.

The benefit is that you can store lots of data in an array, without having to create all the variables. And you can go through the array with a loop, for instant:

For I=0 to 4

Set X[I] = <some value>

A 2 dimensional array, is like an excel document.

A-----B-----C

0-----0-----0

1-----1-----1

2-----2-----2

So to explain that you can imagine that this array we use for storing enemies, so each of the letters would be an enemy.

and for instant row 0 could be the health of the enemy, row 1 the XP you gain from killing it and row 2 whether it can fly or not.

So this way you can store a lot of enemies in an array, and get the data from it. For instant say you need Enemy (C) and you need its health.

So explained simply, you could do "Get C(0)".

3 dimensional array, I don't think is all that common. But to explain it, imagine you have a grid based map of 100x100 tiles. And in this map there are a Ground level, Water level and Air level, which would be the 3rd dimension, and the array would be called X,Y,Z and the 3rd dimension is the Z.

So to explain it.

The X dimension is the tile position in X direction

The Y dimension is the tile position in y direction.

Z is the depth of each tile, in this example it would be 2, since it starts at index 0,1,2. (Water, Ground, Air)

So imagine you wanted to store a flying unit of some sort in the array at position X,Y (10,10), but also a ground unit as well.

Then you could store the flying unit at:

X,Y,Z (10,10, 2)

And the ground unit at:

X,Y,Z (10,10, 1)

So basically that's how you can think of the different arrays and dimensions.