Store 2 variables into a 2D array

Non-platform specific questions.

Store 2 variables into a 2D array

Postby Hblade » Thu Jan 26, 2012 6:32 pm

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?
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: Store 2 variables into a 2D array

Postby skydereign » Thu Jan 26, 2012 6:48 pm

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).
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Store 2 variables into a 2D array

Postby SuperSonic » Thu Jan 26, 2012 8:45 pm

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
A tree never hits an automobile except in self-defence.

Want to use your joystick or controller with Game Editor? Check out my controller engine =D
User avatar
SuperSonic
 
Posts: 1443
Joined: Fri Sep 24, 2010 9:24 pm
Location: Anywhere
Score: 72 Give a positive score

Re: Store 2 variables into a 2D array

Postby Hblade » Fri Jan 27, 2012 8:19 pm

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
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: Store 2 variables into a 2D array

Postby SuperSonic » Sat Jan 28, 2012 12:25 am

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
A tree never hits an automobile except in self-defence.

Want to use your joystick or controller with Game Editor? Check out my controller engine =D
User avatar
SuperSonic
 
Posts: 1443
Joined: Fri Sep 24, 2010 9:24 pm
Location: Anywhere
Score: 72 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest