Advertisement

The Impossible Problem (AKA Need Help)

Started by June 04, 2000 09:41 PM
17 comments, last by valg3 24 years, 3 months ago
Okay, I just got done reading the "Stupid Question" posts and I know this is not a stupid question. I''ve been wrestling with it for two days now! Yes, I''m a newbie to game programming and I''m trying to create a Tetris clone. I''ve created a 2d Array for the main area that the blocks exist, fall, rotate, etc. int GRID[HEIGHT][WIDTH]; If the array value in a spot is 0, nothing is there. If it is a 1, draw a block, etc. Except this is where the problem comes in. The array successfully initializes every spot to 0 as I want. However, it will not at any given time, even in initialization, allow me to set any value in the array to ANYTHING except 0. BTW, I am initializing and checking the array with for loops. Noticing this, I did 2 things. First, I changed the Rendering check loop to make all spots that 0 a visible block. It did it. The peasants rejoiced. Second, I decided to blot out my initialization function, and did the good old difficult way of initializing by declaring it: int GRID[][] = {0,1,0,0,1,0,1.......}; It worked. 1''s were allowed in there, and so were other numbers. But, if I ever use one of my functions that change a value in the array to something other than zero, the program blinks in and out once never running. Has anyone ever run into something like this? I''ve worked with 2d arrays plenty times before, but never saw anything like this. "I'm a man who likes sound ideas..."
Hmm...weird problem, I''ve never experienced this kind of thing before. What exactly are you doing to change the value of a particular cell? Oh yeah, if you have another kind of question like this, try posting to the general and game programming forum, as you''ll probably get better response.

Martin
______________Martin EstevaolpSoftware
Advertisement
Does the program crash or give any errors, or does it just not do anything? You might want to post the code that initializes your array, it sounds like the problem is there. Sounds like a type, pointer or scope error. Tough to say.

Often having someone else look at it will reveal a simple bug. Just don''t post two pages of code: Most people will ignore it if it''s too long.

Some things to think about:
-Verify all types that you are using. The compiler is good at type checking, but sometimes loops don''t get executed (or go on to infinity) because something you thought was an unsigned int was really an int and so on.

-In the loop where you check your array values, make sure you are checking the right thing. It sounds stupid, but it''s a mistake we''ve all made (I had a similar problem once, and to check values I was outputting them to the screen. Why were they always the same? Why wasn''y my init code working? Turns out I had made a typo in the printf statement...it wasn''t printing the array values properly. The array was being initialized fine.).
------When thirsty for life, drink whisky. When thirsty for water, add ice.
Graylien, I did check to make sure the array was initialized properly. To do that I made my render function draw a block for each zero it came across. Turns out the entire grid filled with blocks. So I know that it is initialized good. But, if I initialize a shape object parts of the grid array are set to 1, and that kills the program. No errors are displayed, it just goes into the new display mode for fullscreen, and before anything is drawn the entire thing returns to windows. Really odd,especially becauseit only happens when I fool with changing an array value.

Here''s the initializtion, I''m sure its fine :-)

//////////////////////////////////////////////////////////////////
BOOL resetGRID()
//////////////////////////////////////////////////////////////////
{
//set the initial values of GRID to 0
for(int i = 0; i < HEIGHT; i++)
{
for(int j = 0; j < WIDTH; j++)
{
GRID[j] = 0;
}
}

//check the initial values of GRID to be 0
for(i = 0; i < HEIGHT; i++)
{
for(int j = 0; j < WIDTH; j++)
{
if(GRID[j] != 0)<br> return FALSE;<br> }<br> }<br><br> return TRUE;<br>} </i>
If you ''cut & pasted'' this from your code then you have a problem. I don''t know if this is causing your big problem, but it is a problem.

Your initializing statement should be: GRID[j] = 0;
NOT GRID[j] = 0; as you have it.

The compiler probably initializes your array to 0 anyway and your procedure is only initializing the 0 - j elements.
_______________________________
"To understand the horse you'll find that you're going to be working on yourself. The horse will give you the answers and he will question you to see if you are sure or not."
- Ray Hunt, in Think Harmony With Horses
ALU - SHRDLU - WORDNET - CYC - SWALE - AM - CD - J.M. - K.S. | CAA - BCHA - AQHA - APHA - R.H. - T.D. | 395 - SPS - GORDIE - SCMA - R.M. - G.R. - V.C. - C.F.
OK, I looked at my post and I got the same error you did. Therefore, your code is probably OK. The HTML interpreter isn''t letting us see that initialization statement correctly.

Back to square one.
_______________________________
"To understand the horse you'll find that you're going to be working on yourself. The horse will give you the answers and he will question you to see if you are sure or not."
- Ray Hunt, in Think Harmony With Horses
ALU - SHRDLU - WORDNET - CYC - SWALE - AM - CD - J.M. - K.S. | CAA - BCHA - AQHA - APHA - R.H. - T.D. | 395 - SPS - GORDIE - SCMA - R.M. - G.R. - V.C. - C.F.
Advertisement
OK, maybe this is a stupid thought, but what is HEIGHT and WIDTH #defined as. If they are defined as 0 that would account for the problem.
_______________________________
"To understand the horse you'll find that you're going to be working on yourself. The horse will give you the answers and he will question you to see if you are sure or not."
- Ray Hunt, in Think Harmony With Horses
ALU - SHRDLU - WORDNET - CYC - SWALE - AM - CD - J.M. - K.S. | CAA - BCHA - AQHA - APHA - R.H. - T.D. | 395 - SPS - GORDIE - SCMA - R.M. - G.R. - V.C. - C.F.
bishop_pass, yea I noticed that GRID[j] thing. I fixedit and I''m still having my big problem with it. I''ve never had an array act like this before :-(

I''m still messing with it, and stillopen to suggesstions.
Here''s my HEIGHT and WIDTH

#define HEIGHT 15
#define WIDTH 9

And I''ve tried them as "const int" too. SO I know #define isnt the problem.
What do your "Changing" functions look like?
And your rendering function?
It seems like you are causing a general protection fault or something, accessing data beyond the end of the array.

It''s hard to tell - nothing is wrong with the code you posted ( except that the boards mangled it ; ) ) as far as I can tell....



#pragma DWIM // Do What I Mean!
~ Mad Keith ~
It's only funny 'till someone gets hurt.And then it's just hilarious.Unless it's you.

This topic is closed to new replies.

Advertisement