Page 1 of 1

Store 2 variables into a 2D array

PostPosted: Thu Jan 26, 2012 6:32 pm
by Hblade
Can this be done?
Storing the information of 2 variables into a 2D array. Example:
Code: Select all
array[var1][var2]


Would this even be useful?

Re: Store 2 variables into a 2D array

PostPosted: Thu Jan 26, 2012 6:48 pm
by skydereign
Not sure what you mean by store variables into the array. Of course a 2d array could store two variables, or any even number. As for your code bit, that use is extremely useful in grid based games. You store some value according to two unique indexes, for example the actor's X on the grid and Y on the grid (X and Y are grid coordinates, not real coordinates). This is also how you set up your own tile map maker (each position in the array [X][Y] holds the value of what tile should be created there).

Re: Store 2 variables into a 2D array

PostPosted: Thu Jan 26, 2012 8:45 pm
by SuperSonic
Try doing this

Code: Select all
int array[var1][var2][2];


That way, for each spot in your 2d array, you have 2 different values. You can access them like this:

Code: Select all
array[i][j][0];//access the first value
array[i][j][1]//access the second value


Is that what you were looking for? :D

Re: Store 2 variables into a 2D array

PostPosted: Fri Jan 27, 2012 8:19 pm
by Hblade
Ah thanks super :) This is what I was looking for. Though honestly I may have had a brain fart but for some reason even now it still seems important O_o strange xD

Re: Store 2 variables into a 2D array

PostPosted: Sat Jan 28, 2012 12:25 am
by SuperSonic
Hblade wrote:Ah thanks super :) This is what I was looking for. Though honestly I may have had a brain fart but for some reason even now it still seems important O_o strange xD

xD
Glad I could help :D