Archived

This topic is now archived and is closed to further replies.

Stibmit

dumb question with a 2d array

Recommended Posts

Stibmit    122
Ugh. Boy am I feeling like a dumbie tonight. Anyways, I''m not really thinking straight, and I''m having a hard time with this 2d array that I''m working with. First, here''s the source:
  
char Array_1[12][16] =
	{
			{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
			{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
			{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
			{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
			{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
			{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
			{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
			{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
			{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
			{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
			{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
			{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}
	}; //end char Array_1


	for(int count_y=0; count_y <= 12; count_y++)
	{
		for(int count_x=0; count_x <= 16; count_x++)
		{
			tile_x = Array_1[0][count_x];
			tile_y = Array_1[count_y][0];

		} //end for(x)

		
	} //end for(y)

  
Basically, what I want to happen is for the the for loops to run through that big 2D array, and then have tile_x equal the x counter, and tile_y equal the y counter. For some reason, I can''t seem to wrap my head around it, I''m getting some really weird results, where sometimes where tile_x is supposed to equal 0, it actually equals 1, and a whole bunch of other odd things. I know I''m doing something very wrong. Can someone give me a hand?

Share this post


Link to post
Share on other sites
Stibmit    122
Thanks for the help, but I''m still having the same problem unfortunately
I''ll try to better explain what happens when I change some of the array''s values around. If you look at the last two lines of the array, you can see that there are two rows of 1''s. However, if I change one of the rows first value to 0, when I read in the array''s values, the rest of the values in that row appear to be 0, even though I intended their values to be 1.

Even with the small change of <= to just <, I get the same problem. Thanks again for the help, just a little further maybe and I''ll have it

Share this post


Link to post
Share on other sites
F104    130
I think I found the error...

with "tile_x = Array_1[0][count_x];" you only traverse the first row of values even if count_y changes; and with "tile_y = Array_1[count_y][0];" you do the opposite: you only read the first value of all the rows!

You''re actually reading only the top and left border of the "square"...

I don''t know what you want to do exactly, but I think you should use the two indexes (count_x, count_y) together!

Bye Bye
F104/NA

Share this post


Link to post
Share on other sites
Stibmit    122
There''s a lot more going on in the source than what I showed- the things I cut out to make things more simple was everything to do with DirectDraw that I had going on, since my problem has nothing to do with DirectDraw. Basically, what I want to do, is display a tile for every single value of the 2D array, where 0 represents a tile, and 1 represents another. That''s what I cut out, and that is what''s working- however, I still can''t seem to get the damn array stuff working I''m getting weird values, I don''t think I''m doing the counting right, where I read in the values for x and y. Basically, what I want to happen is to read in the x value''s for the array, and then read in the y values for the array, and then display them. I KNOW I''m doing something wrong, because I''m getting tiles where I shouldn''t get them. Thanks for the help though Can anyone offer any more suggestions?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
I m not sure to understand the question but if I m right... what you want is that your function gives U the table value ...


just do that loop
for(int count_y=0; count_y <= 12; count_y++) { for(int count_x=0; count_x <= 16; count_x++)
{
value = Array_1[count_y][count_x]; } //end for(x)
} //end for(y)

or if U want to have only the counter value

for(int count_y=0; count_y <= 12; count_y++) { for(int count_x=0; count_x <= 16; count_x++)
{
tile_x = count_x;
tile_y = count_y;//or just use the count value
} //end for(x)
} //end for(y)


That seems to easy but it s what I understand about your question.

Sorry if it wasn t your problem

Bye bye

manumoi

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
dont forget to use < instead of <= as oluseyi said

Share this post


Link to post
Share on other sites