A switch that doesn't switch

This is a discussion on A switch that doesn't switch within the C++ Programming forums, part of the General Programming Boards category; I'm trying to blt a surface depending on a value in an array, but nothing gets blted. Can anyone let ...

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    180

    A switch that doesn't switch

    I'm trying to blt a surface depending on a value in an array, but nothing gets blted. Can anyone let me know whats wrong? Because I can't figure it out for the life of me!
    BTW, tile.TileInformation[k][i] is an int

    Code:
    //tile macros
    #define ID_GRASS 1
    #define ID_DIRT 2
    #define ID_FLOWER 3
    ...
    //generate random terrain data
           for(int k = 0;k<25;k++)
           {
                   for(int i = 0; i<19;i++)
                   {
                           tile.TileInformation[k][i] = 1;//Random_Range(1,3);  //fill our array with random values
    
                   }
    
           }
    ...
    for(int y = 0;y<25;y++)
           {
                   for(int x = 0; x<19;x++)
                   {
                           switch(tile.TileInformation[x][y])
                           {
                                   case ID_GRASS:
                                           tile.Grass.dest_rect.left = y*32;
                                           tile.Grass.dest_rect.right = tile.Grass.dest_rect.left + 32;
                                           tile.Grass.dest_rect.top = x*32;
                                           tile.Grass.dest_rect.bottom = tile.Grass.dest_rect.top + 32;
    
                                           DDback->Blt(&tile.Grass.dest_rect,//destination rectangle(coords)
                                                           tile.Grass.DDTile, //our DD surface
                                                           &tile.Grass.src_rect,//source RECT
                                                           DDBLT_WAIT,NULL); //params
    
                                           break;
    
                                   case ID_DIRT:
                                           tile.Dirt.dest_rect.left = y*32;
                                           tile.Dirt.dest_rect.right = tile.Dirt.dest_rect.left + 32;
                                           tile.Dirt.dest_rect.top = x*32;
                                           tile.Dirt.dest_rect.bottom = tile.Dirt.dest_rect.top + 32;
    
                                           DDback->Blt(&tile.Dirt.dest_rect,//destination rectangle(coords)
                                                           tile.Dirt.DDTile, //our DD surface
                                                           &tile.Dirt.src_rect,//source RECT
                                                           DDBLT_WAIT,NULL); //params
    
                                           break;
    
                                   case ID_FLOWER:
                                           tile.Flower.dest_rect.left = y*32;
                                           tile.Flower.dest_rect.right = tile.Flower.dest_rect.left + 32;
                                           tile.Flower.dest_rect.top = x*32;
                                           tile.Flower.dest_rect.bottom = tile.Flower.dest_rect.top + 32;
    
                                           DDback->Blt(&tile.Flower.dest_rect,//destination rectangle(coords)
                                                           tile.Flower.DDTile, //our DD surface
                                                           &tile.Flower.src_rect,//source RECT
                                                           DDBLT_WAIT,NULL); //params
    
                                           break;
    
                           }
                           
                   }
           }

  2. #2
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    Hm...well in your first loop you use k for the outer and i for the inner with tile.TileInformation[k][i]

    In the second loop you use y for the outer and x for the inner with tile.TileInformation[x][y]

    try:
    Code:
    //...
    switch(tile.TileInformation[y][x])
    //...
    edit: actually your first loop could have been the problem too since I don't know the dimensions of the array
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  3. #3
    Registered User
    Join Date
    Mar 2004
    Posts
    180
    OK, thx, I'll try that

  4. #4
    Registered User
    Join Date
    Mar 2004
    Posts
    180
    That didn't seem to make a difference. Here are the array values/sizes
    Code:
    class Tile
    {
    public:
            RECT src_rect, dest_rect; //source and dest rectangles
            LPDIRECTDRAWSURFACE7 DDTile; // contains the surfaces which contain the BMP files
    };
    
    class TileSet
    {
    public:
      int TileInformation[25][19];  //contains data such as invalid tiles
      Tile Grass;
      Tile Flower;
      Tile Dirt;
    
    };

  5. #5
    Cheesy Poofs! PJYelton's Avatar
    Join Date
    Sep 2002
    Location
    Boulder
    Posts
    1,728
    Have you tried using the debugger to follow the code or maybe adding something like messageboxes within each switch section to see if whether or not it ever actually reaches the blt statements? That way we know if the problem is with the switch or with the blt statements themselves.

  6. #6
    Registered User
    Join Date
    Mar 2004
    Posts
    180
    Ok, I just tried that. I put breakpoints in all of the switch cases. And somthing is definatly wrong. It drops into the first switch like it should, excecuts the first statment, misses the second, hits the third, the forth, skips to the second, skips to the forth, back to the first, etc etc. Occacisonaly x incremits.

    What could cause this?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Data Structure Eror
    By prominababy in forum C Programming
    Replies: 3
    Last Post: 01-06-2009, 08:35 AM
  2. ascii rpg help
    By aaron11193 in forum C Programming
    Replies: 18
    Last Post: 10-29-2006, 01:45 AM
  3. Switch
    By cogeek in forum C Programming
    Replies: 4
    Last Post: 12-23-2004, 05:40 PM
  4. Switch Case
    By FromHolland in forum C++ Programming
    Replies: 7
    Last Post: 06-13-2003, 03:51 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21