I can't explain this

This is a discussion on I can't explain this within the C++ Programming forums, part of the General Programming Boards category; okay I am making a very nice tile engine using a class for the map and a structure for each ...

  1. #1
    Banned frenchfry164's Avatar
    Join Date
    Oct 2001
    Posts
    1,552

    I can't explain this

    okay I am making a very nice tile engine using a class for the map and a structure for each tile and NPC. It will have lighting effect, 3 layers, weather, etc. But anyways, I'm having problems with my code.

    I use fstream to load in the map files, and it loads everything in okay except the tiles. Well, actually the tiles DO load correctly, but if I try to read the tile's value from another function it always thinks it's 0. But if I call it from within the function I load with, it gets the right value. Here is the source that loads the maps, my map class, and the function I am using to fetch the value of the tiles.

    Code:
    #define MTX 60
    #define MTY 45    // Max Deminsions
    #define ML 3
    
    ...
    
    typedef class map
    {
     private:
     BITMAP *MapDrawBuffer;
     tile tiles[MTX][MTY][ML];
     int width, height;
     int camerax, cameray;
     char *MapFileName;
     char MapName[256];
     bool ExcludeSecondLayer;
     public:
     void LoadMap(char *file);
     int GetTileType(int positX, int positY, int positL);
    };
    Code:
       int LoadPositionX = 0;
       int LoadPositionY = 0;
       
       for (int i=0; i <= height; i++)
       {
        for (int j=0; j <= width; j++)
        {
         MapFile >> buffer;
         clear(screen);
         tiles[LoadPositionX][LoadPositionY][0].type = atoi(buffer);
         textprintf(screen,font,0,0,makecol(255,255,255),"%i",tiles[LoadPositionX][LoadPositionY][0].type);
         LoadPositionX++;
        }
        
        LoadPositionX = 0;
        LoadPositionY++;
       }
    Code:
    int map::GetTileType(int positX, int positY, int positL)
    {
     return tiles[positX][positY][positL].type;
    }
    Code:
     map CurrentMap;
     CurrentMap.LoadMap("test.tmf");
     clear(screen);
     textprintf(screen,font,5,5,makecol(255,255,255),"%i",CurrentMap.GetTileType(4,3,0));
     readkey();
    Sorry if that didn't copy over right. But what is strange is, if you look at the function that loads the map, it has a textprintf, which is Allegro's text function for graphics mode writing, and it displays the tile's type value. And it works perfectly inside the function that loads the map. But when I try to use GetTileType to do it, it ALWAYS gives me 0 no matter what.

  2. #2
    Registered User The Dog's Avatar
    Join Date
    May 2002
    Location
    Cape Town
    Posts
    788
    I'm not sure what code is for what.

    Could you please clarify.

  3. #3
    Banned frenchfry164's Avatar
    Join Date
    Oct 2001
    Posts
    1,552
    the first one is the map class the second one is the section of LoadMap() that loads the tiles the third one is the one that gets the value of the tiles (since tiles is declared private) and the last one is where I load a map and try to retrieve a value.

  4. #4
    Registered User The Dog's Avatar
    Join Date
    May 2002
    Location
    Cape Town
    Posts
    788
    I haven't seen %i before, what is that specifier?

  5. #5
    Banned frenchfry164's Avatar
    Join Date
    Oct 2001
    Posts
    1,552
    integers

  6. #6
    Registered User The Dog's Avatar
    Join Date
    May 2002
    Location
    Cape Town
    Posts
    788
    try using %d

  7. #7
    Banned frenchfry164's Avatar
    Join Date
    Oct 2001
    Posts
    1,552
    same results

  8. #8
    Registered User
    Join Date
    Oct 2001
    Posts
    68

    Are you using binary stream for fstream

    Hi U,

    Are you using binary stream for fstream(), if so that it is fine. But if you are using ios::in then try ios::binary....And let me know what it does

    Thanks
    Partik Parikh

  9. #9
    Banned frenchfry164's Avatar
    Join Date
    Oct 2001
    Posts
    1,552
    same results

  10. #10
    Banned frenchfry164's Avatar
    Join Date
    Oct 2001
    Posts
    1,552
    like I said b4, it IS loading correctly, because there is a textprintf() that displays the value of the type member of tiles, not the buffer itself. So somehow it loses the value of the type member or something.

  11. #11
    Registered User
    Join Date
    Oct 2001
    Posts
    68
    I can't do much you have to try tracing the code

  12. #12
    Registered User The Dog's Avatar
    Join Date
    May 2002
    Location
    Cape Town
    Posts
    788
    the only thing i can see is this:

    if you haven't typedef'ed the int to tile, then make GetTileType() return a tile instead.

  13. #13
    Banned frenchfry164's Avatar
    Join Date
    Oct 2001
    Posts
    1,552
    type is an int

    here is the tile structure:

    PHP Code:
    typedef struct tile
    {
     
    int type;
     
    int AniFrame;
     
    bool lit;
    }; 

  14. #14
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,600
    Try this:

    if(!CurrentMap.GetTileType(4,3,0))
    MessageBox(NULL, "The Value Is Indeed Zero", "", 0);
    else
    MessageBox(NULL, "The Value Is Non-Zero", "", 0);


    Then, if it's non-zero, try:

    int type = CurrentMap.GetTileType(4,3,0);

    textprintf(screen,font,5,5,makecol(255,255,255),"% i",type);

    If nothing do:

    textprintf(screen,font,5,5,makecol(255,255,255),"% g",type);

    Just a suggestion.
    Code:
    if( numeric_limits< byte >::digits != bits_per_byte )
        error( "program requires bits_per_byte-bit bytes" );
    24bbs.cpp

  15. #15
    Registered User
    Join Date
    Oct 2001
    Posts
    68
    I am new to Image Processing and window so i don't understand these

Page 1 of 3 123 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can you explain these bitwise operations?
    By 6tr6tr in forum C++ Programming
    Replies: 6
    Last Post: 10-29-2008, 01:19 PM
  2. Please explain?
    By neo_phyte in forum C Programming
    Replies: 3
    Last Post: 08-25-2006, 05:23 AM
  3. Can someone explain to me what this code means
    By Shadow12345 in forum C++ Programming
    Replies: 3
    Last Post: 12-22-2002, 11:36 AM
  4. Replies: 4
    Last Post: 11-19-2002, 08:18 PM
  5. Can someone explain "extern" to me?
    By valar_king in forum C++ Programming
    Replies: 3
    Last Post: 09-16-2001, 12:22 AM

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