Thread: Unsure how to fix this error

  1. #1
    Banned SniperSAS's Avatar
    Join Date
    Aug 2005
    Posts
    175

    Unsure how to fix this error

    Code:
    #define tile ( bool hardness, char symbol, int color, int visibility )
    #include <iostream>
    #include <cstdlib>
    #include <time.h>
    #include <windows.h>
    
    using namespace std;
    
    class DrawMap
    {
          public:
                 void Set_Map( int *tile, void *MapBuffer[1][1], int Xcoord, int Ycoord, int Xmax, int Ymax );
                 void SetMapSize( int Ymax, int Xmax );
                 DrawMap();
                 void Draw_Map( int *tile, int *MapBuffer[1][1], int Xcoord, int Ycoord, int Xmax, int Ymax );
                 ~DrawMap();
                 int ClearAll( int *tile );
                 void *MapBuffer[1][1];
                 int Ycoord, Xcoord, Ymax, Xmax;
    };
    
    DrawMap::DrawMap(){}
    DrawMap::~DrawMap(){}
    void DrawMap::Set_Map( int *tile, void *MapBuffer[1][1], int Xcoord, int Ycoord, int Xmax, int Ymax ) {
         Xcoord = 0;
         Ycoord = 0;
         while( Ycoord <= Ymax ) {
                Xcoord = 0;
                while( Xcoord <= Xmax ) {
                       MapBuffer[Xcoord][Ycoord] = new tile( false, 50, 9, 5 );  
    
    //                   ^^ This line gives me the errors:
    //                    expected ')' before "hardness"
    //                    expected ';' before "hardness"
                       Xcoord++;
                       if( Xcoord <= 80 ) {
                           Ycoord++;
                           }
         }
         }
    }

    I have only begun writing the code for this game, so that is why it is so incomplete.
    Can anyone tell me how to fix this problem?

    Also, I'm new here, so feel free to burn me on anything I may have done wrong.

  2. #2
    Deprecated Dae's Avatar
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    1,034
    Code:
    #define tile ( bool hardness, char symbol, int color, int visibility )
    Code:
    MapBuffer[Xcoord][Ycoord] = new tile( false, 50, 9, 5 );
    What is that 'tile' macro suppose to do? Right now all it seems to be doing is processing the parameters and then do nothing (ending result is MapBuffer = nothing). Not sure how that resulted in that error, and I could be wrong.. seeing as I never use macros. Do you have a 'tile' function around? because that would seem better to use (especially since this is C++).
    Warning: Have doubt in anything I post.

    GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > void *MapBuffer[1][1];
    What exactly are you hoping to store here?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Banned SniperSAS's Avatar
    Join Date
    Aug 2005
    Posts
    175
    It seems i shouldn't be using a macro.

    This is hard to explain, but what i was planning on doing was having the SetMapSize function say how big the MapBuffer array of points would be, then have another function change the variables inside of the tile macro that MapBuffer pointed too.

    Would I have been able to do that with a macro, and if not, what should I be doing here?

    Thanks for the help, guys.

  5. #5
    Deprecated Dae's Avatar
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    1,034
    Code:
    void DrawMap::Set_Map( int *tile, void *MapBuffer[1][1], int Xcoord, int Ycoord, int Xmax, int Ymax ) {
         Xcoord = 0;
         Ycoord = 0;
    Well, first I think you meant to have that Xcoord and Ycoord variables in the constructor, because with them there you are changing the variables to 0 even if you say put 5 in the Set_Map function when call it, so theres no point in even asking for the xcoord and ycoord in that parameter.

    Furthermore if you put a number smaller than 80 in the parameter for Xmax, then the loop would never end, causing quite a fun bug to find. Instead of using this if statement to end it:

    Code:
                       if( Xcoord <= 80 ) {
                           Ycoord++;
                           }
    I would change the while statement all together to:

    Code:
         while( Ycoord <= Ymax ) {
                Xcoord = 0;
                while( Xcoord <= Xmax && Xcoord <= 80 ) {
                       MapBuffer[Xcoord][Ycoord] = new tile( false, 50, 9, 5 );  
    
    //                   ^^ This line gives me the errors:
    //                    expected ')' before "hardness"
    //                    expected ';' before "hardness"
                       Xcoord++;
         }
         Ycoord++;
         }
    I changed the while statement so it will never go past 80, and made sure when it ends it increments Ycoord.

    --------------------------------------------------------------------

    On trying to figure out what you wanted your code to do, I remodded your code, and its pretty much my own code now.. completely changed. It works though, check it out and see how its done. Theres no macros in any of my code, theres an alternative for mostly every macro scenario thats safer/better/easier/more clear.

    It would have been much easier using a normal 1 dimension array, but since its 2 dimensions you need to know special rules on how 2 dimension arrays work. I read it in Data Structures for Game Programmers myself, great book to start on the basics of how to lat out your classes for games, which basic choices to make, and a good thing to read before learning STL.

    To make the 2 dimension array, its simply the first multiplied by the second ([1][1] has 1 spot, [1][2] has 2 spots, see its just multiplied). To access a spot in the 2 dimension array, its the first spot you want to access, multiplied by the highest second spot (in a [10][30] type array, it would be 30), added to the second spot you are trying to access. eg. you want to access spot [4][6] in array [10][20], then the formula is 4 * 20 + 6. Look at the array: m_mapBuffer to see what I mean, thats a 2d array but to use it you have to use that formula instead of the normal [][].

    With that said..

    Code:
    #include <iostream>
    
    enum RAINBOW {red, blue, green, orange, yellow, purple, pink, etc};
      
    struct STile
    {
      bool hardness;
      char symbol;
      enum RAINBOW color;
      int visibility;
    };
    
    
    class CDraw_Map
    {
    private:
      int m_yMax;
      int m_xMax;
      int m_xCoord;
      int m_yCoord;
    
      STile* m_mapBuffer;
    
    public:
      CDraw_Map () {} /* put this version here incase you dont want to give parameters on construction of object */
      CDraw_Map (int, int); /* this version allows setting the size of the map on construction */
      ~CDraw_Map ();
    
      void DrawMap ();
      void SetMapSize (int, int); /* alternate way to set map size, used when resizing, or not using the (int, int) constructor. */
      void SetTile (int, int, bool, char, enum RAINBOW, int);
      void SetAllTiles (bool, char, enum RAINBOW, int);
      int ClearAllTiles ();
      
      void CoutTile (int, int); //temporarily used to check if functions worked
    };
    
    CDraw_Map::CDraw_Map (int p_yMax, int p_xMax) : m_yMax(p_yMax), m_xMax(p_xMax)
    {
      m_mapBuffer = new STile[p_yMax * p_xMax];
    }
    
    CDraw_Map::~CDraw_Map ()
    {
    }
    
    void CDraw_Map::SetTile (int p_yCoord, int p_xCoord, bool p_hardness, char p_symbol, enum RAINBOW p_color, int p_visibility)
    {
      m_mapBuffer[p_yCoord * m_yMax + p_yCoord].hardness = p_hardness;
      m_mapBuffer[p_yCoord * m_yMax + p_yCoord].symbol = p_symbol;
      m_mapBuffer[p_yCoord * m_yMax + p_yCoord].color = p_color;
      m_mapBuffer[p_yCoord * m_yMax + p_yCoord].visibility = p_visibility;
    }
    
    void CDraw_Map::SetAllTiles (bool p_hardness, char p_symbol, enum RAINBOW p_color, int p_visibility)
    {
      for (int i = 0; i < m_yMax; ++i) {
        for (int j = 0; j < m_xMax; ++j) {
          m_mapBuffer[i * m_yMax + j].hardness = p_hardness;
          m_mapBuffer[i * m_yMax + j].symbol = p_symbol;
          m_mapBuffer[i * m_yMax + j].color = p_color; 
          m_mapBuffer[i * m_yMax + j].visibility = p_visibility;
        }
      }
    }
    
    void CDraw_Map::CoutTile (int p_yCoord, int p_xCoord)
    {
      std::cout << m_mapBuffer[p_yCoord * m_yMax + p_yCoord].hardness << std::endl;
      std::cout << m_mapBuffer[p_yCoord * m_yMax + p_yCoord].symbol << std::endl;
      std::cout << m_mapBuffer[p_yCoord * m_yMax + p_yCoord].color << std::endl;
      std::cout << m_mapBuffer[p_yCoord * m_yMax + p_yCoord].visibility << std::endl;
    }
    
    void CDraw_Map::SetMapSize (int p_yMax, int p_xMax)
    {
      STile* tempBuffer = new STile[p_yMax * p_xMax];
      m_mapBuffer = tempBuffer;
    
      /* assign the classes private values to the new values */
      m_yMax = p_yMax; 
      m_xMax = p_xMax;
    }
    
    int main ()
    {
      CDraw_Map Map1(20, 20);
      
      Map1.SetTile(10, 12, 0, 'C', blue, 9);
    
      Map1.CoutTile(10, 12);
      
      Map1.SetAllTiles(1, 'A', red, 5);
      
      Map1.CoutTile(0, 0);
    
      std::cin.get();
    }
    I included that main () simply for demonstration, along with the method CoutTile ().

    I would suggest, when you are beginning, to take things 1 step at a time. I could have written almost this entire thing by simply starting off with a [50][50] array and then worrying about how to resize it and such after (which is exactly what I did actually).
    Last edited by Dae; 08-21-2005 at 04:09 PM.
    Warning: Have doubt in anything I post.

    GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101

  6. #6
    Banned SniperSAS's Avatar
    Join Date
    Aug 2005
    Posts
    175
    Thanks man, and just so you don't think I'm a complete idiot, the code I showed you guys was nowhere near being finished.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  3. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  4. Learning OpenGL
    By HQSneaker in forum C++ Programming
    Replies: 7
    Last Post: 08-06-2004, 08:57 AM
  5. pointer to array of objects of struct
    By undisputed007 in forum C++ Programming
    Replies: 12
    Last Post: 03-02-2004, 04:49 AM