Skip to main content
gamedev.net
🔒 Locked

Problem with a 2-Dimensional Array :/ ....

Started by Anachronism 1 reply 150+ views
Original Post
Anachronism
Anachronism
Hello, Thanks for looking. I hope this is enough information to describe my problem. I'm not having any compile errors. Must be logic. Basically the purpose of this array is to draw a 2dimensional grid of blocks... I initialize this array:
  
    char gfield[17][12] =
   {{'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'},
    {'1','1','1','1','1','1','1','1','1','1','1','1'}};
  
Each character will designate a block that I am drawing. If it is a blank space, i don't want to draw a block on the screen. If a certain array element is a 1, I want to draw a block there. So the array above should draw a border of blocks around the gamefield. (with no top) Well, this is my loop where I draw the blocks.
  
void gamefield::drawfield(void) {

    for(int row = 0; row <= 11; row++) {
        
        for(int col = 0; col <= 16; col++) {
        
           if(gfield[row][col] != ' ') {

                drawBlock((float)row, (float)col, -20.0f);

           }

        }

    }

}
  
The problem is, EVERY block is drawn. Even all of the spaces. It should draw only the outside border of ones. If I change the If statement to: if(gfield[row][col] == ' ') It draws NO blocks. Any ideas where my logic error could be? I have individually placed the drawing blocks in each location so I know my drawing routine (drawBlocks) is fine. The problem has to be in one of these sections of code. Any ideas? Any help would be greatly appreciated. Thanks... -Dennis EDIT: Added source tags. [edited by - anachronism on December 18, 2002 10:39:10 PM]
CWizard
CWizard
Test if it works if you use this condition:
if(gfield[row][col] == ''1'')
drawBlock((float)row, (float)col, -20.0f);
Then I suggest, it would be better to have numerical codes instead. That is, like this:
{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},

A possibility is that your array (pointer) is garbage, so you check some random memory. The best way is to step into the debugger and see what values you are checking with.


Anachronism
Anachronism
Thaaaaat''ll do it!

Thanks for the help man. I appreciate it.

-Dennis

Topic Locked

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

Sign in to reply to this topic.