Skip to main content
gamedev.net
🔒 Locked

Code Question

Started by Malikive May 12, 2003 at 8:03 PM 5 replies 450+ views
Original Post
Malikive
Malikive
Ok, normally I can figure small things like this out but this one evades me.... I''ve got code something like this....
  
int		Block_Array[7][4][4][4]; // [Block Number][Frame Number][Rows][Columns]

  
...as a global integer array... ...Initialized ONCE in GAME_INIT like so...
  
for (int zblocknum = 0; zblocknum <7; zblocknum++)
	{
		for (int zframenum = 0; zframenum < Block[zblocknum].Max_Frames; zframenum++)
		{
			for (int zrow = 0; zrow <4; zrow++)
			{
				for (int zcolumn = 0; zcolumn <4; zcolumn++)
				{
					Block_Array[zblocknum][zframenum][zrow][zcolumn] = 0;
				}
			}
		}
	}
// Defines Straight Piece....BLOCK 0

		Block_Array[0][0][0][1] = 1;
		Block_Array[0][0][1][1] = 1; 
		Block_Array[0][0][2][1] = 1; 
		Block_Array[0][0][3][1] = 1;

//... There are more Block_Array definitions, but I won''t list them all here...they are similar to the above

  
...The ONLY TIME I ever use this in my Game_Main is with this code for comparing reasons
  
	for (x = 0; x < 4; x++)
		{
			for (y = 0; y < 4; y++)
			{					
				if (Block_Array[Blocknum][Block[Blocknum].current_frame][x][y] == 1)
				Block_Board[Block[Blocknum].row+1 +x][Block[Blocknum].column+1 +y] = Blocknum;
			}
		}
  
Now everything seems ok up until the end of my program....When I loop the program, I don''t reset the Array variables because I shouldn''t have to but IT CHANGES somehow when I only used it to compare... This is a Tetris clone if you can''t tell by the Block Arrays yet, but it baffles me how Block_Array changes if I only ever use it to compare... I print out the Block_Array (which is filled with 0''s or 1''s) and End up with things like this...
0 1 0 0
0   0 0
0 1 0 0
0 1 0 0 

or

0 1   
0 1 0 0
0 1 0 0
0 1 0 0

 
This only holds true for Block_Array[0][0][...][...], but it''s holding back my progress... ANY INSIGHT to why it may be causing this, I would definitely appreciate, sorry for the long post but if any more info is needed please post. Thanks! Josh
Dave Hunt
Dave Hunt
You are probably writing beyond the bounds of the Block_Board array which could cause it to extend into the beginning of the Block_Array array.

For example, if Block_Board was a 4x4 array and the current Block.row was 3, then your current Block.row+1 would put it beyond the end of the Block_Board bounds.
Malikive
Malikive
Hot DOG!!! You hit the nail right on the head....that''s exactly what I was doing! The variable defined right before Block_Array was being overloaded so I guess it moved right on outta that memory allocation and into my Block_Array allocation.

Now I can take the cheap code out of my game and say it WORKS!

Thanks Dave!

-Josh-
Dave Hunt
Dave Hunt
AP: Was there a particular reason you felt the expletive should not remain uninserted?
Malikive
Malikive
Wow, thanks for that tip, it cleaned up at least that one small segment of my code. I appreciate the help but have to agree with Dave that the cursing could be dismissed.

Peace,

-Josh-

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.