Const int not const in function

This is a discussion on Const int not const in function within the C++ Programming forums, part of the General Programming Boards category; For some unfathomable(to me) reason the 'w' var member in the SDL_Rect object 'Box' below is being set to '0' ...

  1. #1
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,438

    Const int not const in function

    For some unfathomable(to me) reason the 'w' var member in the SDL_Rect object 'Box' below is being set to '0' after the first complete row is drawn, despite it being initialised to Boxsize. i just cant see why it should change?


    Code:
    //header files
    
    const int dwnMax = 60;     
    const int acrMax = 60;     
    
    const int Boxsize = 14;
    const int Boxgap = 1;
    const int Mapsize = 3600;
    
    // other functions 
    
    // other functions 
    
    
    void DrawMap(SDL_Surface *screen, SearchArea mapnode[dwnMax][acrMax])
    {
        int dwn = 0;
        int acr = 0;
        Uint32 color = 0;
        SDL_Rect Box;
        Box.w = Boxsize;                 //this keeps going back to 0 after each complete loop of 'acr'
        Box.h = Boxsize;                  
        Box.x = 0;
        Box.y = 0;
    
        Slock(screen);
    
        for(dwn = 0; dwn < dwnMax; dwn++)
        {
            for(acr = 0; acr < acrMax; acr++)
            {
                if(mapnode[dwn][acr].Walkstate)
                {
                    color = SDL_MapRGB (screen->format, 128, 128, 255);
                }
                else color = SDL_MapRGB (screen->format, 0, 0, 255);
    
                if(mapnode[dwn][acr].STnode)
                {
                    color = SDL_MapRGB (screen->format, 255, 128, 0);
                }
    
                if(mapnode[dwn][acr].TGnode)
                {
                    color = SDL_MapRGB (screen->format, 0, 255, 128);
                }
    
             Box.x += (Boxsize + Boxgap);                                                                           
    
             SDL_FillRect (screen, &Box, color);
            }
            Box.x = 0;
                                                             //  Box.w = 14; adding this line is the only way i can get it working at moment
            Box.y += (Boxsize + Boxgap);
        }
        Sulock(screen);
        SDL_Flip (screen);
    }
    Last edited by rogster001; 09-29-2009 at 05:48 AM.

  2. #2
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,438
    forget this post, fool that i am i was incrementing the Box.x value before i drew anything, i still dont see how that changed the original problem but it needed sorting and has fixed it so...

    changed to this >

    Code:
    SDL_FillRect (screen, &Box, color);
    Box.x += (Boxsize + Boxgap);

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. seg fault at vectornew
    By tytelizgal in forum C Programming
    Replies: 2
    Last Post: 10-25-2008, 02:22 PM
  2. Code review
    By Elysia in forum C++ Programming
    Replies: 71
    Last Post: 05-13-2008, 10:42 PM
  3. About aes
    By gumit in forum C Programming
    Replies: 13
    Last Post: 10-24-2006, 04:42 PM
  4. Game Won't Compile
    By jothesmo in forum C++ Programming
    Replies: 2
    Last Post: 04-01-2006, 04:24 PM
  5. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 10:18 AM

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