🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Multiple dimesion arrays question !!!

Started by
4 comments, last by Metal Typhoon 22 years, 9 months ago
if i declare this int map[3][10][10]; if i want to initialize it would it be some like this ? int map[3][10][10] = {0,0,0,0,0,0,0,0,0,0} {0,0,0,0,0,0,0,0,0,0} {0,0,0,0,0,0,0,0,0,0} {0,0,0,0,0,0,0,0,0,0} {0,0,0,0,0,0,0,0,0,0} {0,0,0,0,0,0,0,0,0,0} {0,0,0,0,0,0,0,0,0,0} {0,0,0,0,0,0,0,0,0,0} {0,0,0,0,0,0,0,0,0,0} {0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0} {0,0,0,0,0,0,0,0,0,0} {0,0,0,0,0,0,0,0,0,0} {0,0,0,0,0,0,0,0,0,0} {0,0,0,0,0,0,0,0,0,0} {0,0,0,0,0,0,0,0,0,0} {0,0,0,0,0,0,0,0,0,0} {0,0,0,0,0,0,0,0,0,0} {0,0,0,0,0,0,0,0,0,0} {0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0} {0,0,0,0,0,0,0,0,0,0} {0,0,0,0,0,0,0,0,0,0} {0,0,0,0,0,0,0,0,0,0} {0,0,0,0,0,0,0,0,0,0} {0,0,0,0,0,0,0,0,0,0} {0,0,0,0,0,0,0,0,0,0} {0,0,0,0,0,0,0,0,0,0} {0,0,0,0,0,0,0,0,0,0} {0,0,0,0,0,0,0,0,0,0}; is this mostly used in little games maps ? like to load a maps and make the colors of it base on the numbers on the array ? "The shortcut is not always the best way " ][v][etal ''][''yphoon
Metal Typhoon
Advertisement
That looks like alot more typing than I would ever recomend. There
are much better ways of zeroing everything if needed. Even if you
just do a simple loop thing you could spare you fingers alot of
pain and suffering. Especialy if you want anything bigger than
[3][10][10] map.
At int map[x][x][x];
you already have your map array ready to recive any value you want
zero or otherwize. I have a question. Does your plan require you
to restrict your map to a set size. If you declare the size at the
start you are limmited to that size for your entire program.
I''m sorry someone will need to clean up after what I''m sain I
reeeeal rustly and just starting to program agian but I have made
a tile engine before(I''m asumming that the map[][][] is for such
a thing.)
You can declare your map as an undefined size by leaving the
[] empty. It may not be that qutie that simple.
I think my compiler forced me to define at least one dimention
of the array at starup. I belive what I did was declare the
array as a one dimentional array and then after I knew what size
i needed I filled it with function like malloc. After I had a
spot in memory I started addressing the array like it was a multi
dimential array. I''m so out of it right now I cant recal all
of the details but I know someone here can easly help you
sort the details out if you want. That way your not nailed down
by any one size map. Hope I understood your need otherwize
Ive rambled like a crazed idiot for no good reason. Ahh
who need a good reason for that anyway.
------------------------------------------------------------- neglected projects Lore and The KeepersRandom artwork
wHAZ uP ???

Zeroing Out every Array at Runtime......

void main()
{
unsigned char Field[3][10][10];
memset((void *)&Field,0,3*10*10);
}
or a other way;

void main()
{
unsigned cahr Field[3][10][10];
unsigned char i,j,k;
for(i=0i;<3;i++)
for(j=0;j<10;j++)
for(k=0;k<10;k++)
Field[j][k]=0;
}

and so on there are many many ways .... to get the result
or zeroing Out every array at Initizialization....
void main()
{
unsigned cahr Field[3][10][10]={0};
}

This Forums has a bug ....
The misatke is in my Post at :
for (...) //i
for( ....) //j
for( ...) //j

Field (i)(j)(k)=0; //Replace here angle brackets with index bracket this is the correct code line , this forzum has a bug with []-Brackets ..........
The easiest way to initialize an array to a single value is to use a function called memset. Here is an example of how it''s used:

memset( map, 0 ,( 3* 10 * 10 * sizeof( int )) );

This would set all values in that array you made to 0.
Joseph FernaldSoftware EngineerRed Storm Entertainment.------------------------The opinions expressed are that of the person postingand not that of Red Storm Entertainment.
In order to get to show up correctly, you have to include in inside of [ source] [ /source] (or ) tags. This is becuase indicates a block of italics.<br><br> <!–STARTSCRIPT–><center><table border=1 cellspacing=0 cellpadding=8 bgcolor="#FFFFFF" width="90%"><tr><td><font color=black face="Courier New"><pre> <br><font color="blue">for</font>(<font color="blue">int</font> i=0; i&lt;3; i++)<br><font color="blue">for</font>(<font color="blue">int</font> j=0; j&lt;10 ;j++)<br><font color="blue">for</font>(<font color="blue">int</font> k=0; k&lt;10; k++)<br>array[<font color="purple">i</font>][<font color="purple">j</font>][<font color="purple">k</font>] = 0;<br> </pre></font></td></tr></table></center><!–ENDSCRIPT–><br> <br><br>Magmai Kai Holmlor<br>- Not For Rent
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara

This topic is closed to new replies.

Advertisement