Page 1 of 1

Array [x,y] or [x][y] or something else?

PostPosted: Fri Feb 19, 2010 5:48 am
by NUTINC
Hello. Could I get an explanation on how to do 2D arrays? I'm trying to design a map that could store the position of objects on it. I know how to do one array with variable[cloneindex] and stuff like that, and I might have to use that or something else, but how does one type an variable with a two dimensional array? Or better yet, how does the two dimensional array system work? :oops:

Re: Array [x,y] or [x][y] or something else?

PostPosted: Fri Feb 19, 2010 6:02 am
by skydereign
Here is a simple 'example'.
Code: Select all
int position[10][2]; // Declaration of  a 2d array

You reference it in the same fashion when setting the values. The 10 in this case would be the actors you are holding the positions of, and the 2 would be the two values you want to hold. Below is one method of storing the positions.
Code: Select all
position[cloneindex][0]=x;
position[cloneindex][1]=y;

Re: Array [x,y] or [x][y] or something else?

PostPosted: Fri Feb 19, 2010 2:33 pm
by Bee-Ant
array[5][5] means an array with 5 arrows and 5 columns. 2D array would draw a table like numbers.

21,34,56,91,27
64,52,13,76,38
21,34,56,91,27
64,52,13,76,38
21,34,56,91,27

Its usually used to handle tile map, clone with so many attributes, etc.

Re: Array [x,y] or [x][y] or something else?

PostPosted: Sat Feb 20, 2010 4:34 am
by NUTINC
Thanks, exactly what I needed. :mrgreen: