Thread: Problem with my building function for my roguelike

  1. #1
    Registered User
    Join Date
    Mar 2012
    Posts
    18

    Problem with my building function for my roguelike

    Hi all,

    as some might know i have been working on a simple roguelike to get better in programming. I am trying to get a function working that will allow a Player to build walls in a dungeon if there isn't allready a wall there.

    However i am getting this error
    Code:
    C:\Users\Thorbenn\RL\Player.cpp||In member function 'void Player::building()':|
    C:\Users\Thorbenn\RL\Player.cpp|300|error: no match for 'operator[]' in '*(((Player*)this)->Player::pMap + ((((unsigned int)((Player*)this)->Player::posx) + 0xffffffffffffffffu) * 1804u))[((Player*)this)->Player::posy]'|
    C:\Users\Thorbenn\RL\Player.cpp|302|error: no match for 'operator[]' in '*(((Player*)this)->Player::pMap + ((((unsigned int)((Player*)this)->Player::posx) + 0xffffffffffffffffu) * 1804u))[((Player*)this)->Player::posy]'|
    C:\Users\Thorbenn\RL\Player.cpp|315|error: no match for 'operator[]' in '*(((Player*)this)->Player::pMap + ((((unsigned int)((Player*)this)->Player::posx) + 1u) * 1804u))[((Player*)this)->Player::posy]'|
    C:\Users\Thorbenn\RL\Player.cpp|317|error: no match for 'operator[]' in '*(((Player*)this)->Player::pMap + ((((unsigned int)((Player*)this)->Player::posx) + 1u) * 1804u))[((Player*)this)->Player::posy]'|
    C:\Users\Thorbenn\RL\Player.cpp|330|error: no match for 'operator[]' in '*(((Player*)this)->Player::pMap + ((unsigned int)(((unsigned int)((Player*)this)->Player::posx) * 1804u)))[(((Player*)this)->Player::posy + -0x000000001)]'|
    C:\Users\Thorbenn\RL\Player.cpp|332|error: no match for 'operator[]' in '*(((Player*)this)->Player::pMap + ((unsigned int)(((unsigned int)((Player*)this)->Player::posx) * 1804u)))[(((Player*)this)->Player::posy + -0x000000001)]'|
    C:\Users\Thorbenn\RL\Player.cpp|345|error: no match for 'operator[]' in '*(((Player*)this)->Player::pMap + ((unsigned int)(((unsigned int)((Player*)this)->Player::posx) * 1804u)))[(((Player*)this)->Player::posy + 1)]'|
    C:\Users\Thorbenn\RL\Player.cpp|347|error: no match for 'operator[]' in '*(((Player*)this)->Player::pMap + ((unsigned int)(((unsigned int)((Player*)this)->Player::posx) * 1804u)))[(((Player*)this)->Player::posy + 1)]'|
    ||=== Build finished: 8 errors, 0 warnings ===|
    and here is my code for the function:
    Code:
    void Player::building()
    {
        cout<<"In what direction do you want to build?";
            char secondAction;
            cin>>secondAction;
            switch(secondAction)
            {
            case'w':
            if(pMap[posx-1][posy]==floor && posx !=1 && posx !=mapx-2 && collectedWalls >0)
            {
                pMap[posx-1][posy]=wall;
                collectedWalls--;
    
            }
           //Linux Version
           // system("clear");
    
           //Windows Version
           system("cls");
            pMap->printMap();
            break;
    
            case's':
            if(pMap[posx +1][posy]==floor && posx !=1 && posx !=mapx-2 && collectedWalls >0)
            {
                pMap[posx +1][posy]=wall;
                collectedWalls--;
    
            }
           //Linux Version
           //system("clear");
    
           //Windows Version
           system("cls");
            pMap->printMap();
            break;
    
            case'a':
            if(pMap[posx][posy -1]==floor && posy !=1 && posy !=mapy-4 && collectedWalls >0)
            {
                pMap[posx][posy-1]=wall;
                collectedWalls--;
    
            }
           //Linux Version
           //system("clear");
    
           //Windows Version
           system("cls");
            pMap->printMap();
            break;
    
            case'd':
            if(pMap[posx][posy +1]==floor && posy !=1 && posy !=mapy-4 && collectedWalls >0)
            {
                pMap[posx][posy+1]=wall;
                collectedWalls--;
    
            }
           //Linux Version
           //system("clear");
    
           //Windows Version
           system("cls");
            pMap->printMap();
            break;
    
            }
    }
    Player Class:
    Code:
    class Player
    {
    private:
    
        string name;
        int level;
        int healthMax;
        int health;
        int dexterty;
        int strength;
        int endurance;
        int defense;
        int exp;
        int expMax;
        int pgold;
        int collectedWalls;
        //Player Location
        int posx;
        int posy;
        int x;
        int y;
        Map* pMap;
    
    public:
        //Constructor
        Player();
        //Destructor
       // ~Player();
    
        void newPlayer();
        void levelUp();
        void setHealth(int healthBonus);
        void movement();
        void attack();
        void viewCharacter();
        void building();
        void mineing();
        void setMap(Map* Dungeon);
    
    };
    Map Class:
    Code:
    class Map
    {
    
      public:
      char map[mapx][mapy];
    
      void genMap();
      void printMap();
    
    
    };
    mapx and mapy are constants for all to reach mapx is a int with value of 22 and mapy a integer with value of 88.

    floor, wall or so are also const chars which are reachable for all.

  2. #2
    Registered User
    Join Date
    Mar 2012
    Posts
    18
    Quote Originally Posted by Thorbenn View Post
    Hi all,

    as some might know i have been working on a simple roguelike to get better in programming. I am trying to get a function working that will allow a Player to build walls in a dungeon if there isn't allready a wall there.

    However i am getting this error
    Code:
    C:\Users\Thorbenn\RL\Player.cpp||In member function 'void Player::building()':|
    C:\Users\Thorbenn\RL\Player.cpp|300|error: no match for 'operator[]' in '*(((Player*)this)->Player::pMap + ((((unsigned int)((Player*)this)->Player::posx) + 0xffffffffffffffffu) * 1804u))[((Player*)this)->Player::posy]'|
    C:\Users\Thorbenn\RL\Player.cpp|302|error: no match for 'operator[]' in '*(((Player*)this)->Player::pMap + ((((unsigned int)((Player*)this)->Player::posx) + 0xffffffffffffffffu) * 1804u))[((Player*)this)->Player::posy]'|
    C:\Users\Thorbenn\RL\Player.cpp|315|error: no match for 'operator[]' in '*(((Player*)this)->Player::pMap + ((((unsigned int)((Player*)this)->Player::posx) + 1u) * 1804u))[((Player*)this)->Player::posy]'|
    C:\Users\Thorbenn\RL\Player.cpp|317|error: no match for 'operator[]' in '*(((Player*)this)->Player::pMap + ((((unsigned int)((Player*)this)->Player::posx) + 1u) * 1804u))[((Player*)this)->Player::posy]'|
    C:\Users\Thorbenn\RL\Player.cpp|330|error: no match for 'operator[]' in '*(((Player*)this)->Player::pMap + ((unsigned int)(((unsigned int)((Player*)this)->Player::posx) * 1804u)))[(((Player*)this)->Player::posy + -0x000000001)]'|
    C:\Users\Thorbenn\RL\Player.cpp|332|error: no match for 'operator[]' in '*(((Player*)this)->Player::pMap + ((unsigned int)(((unsigned int)((Player*)this)->Player::posx) * 1804u)))[(((Player*)this)->Player::posy + -0x000000001)]'|
    C:\Users\Thorbenn\RL\Player.cpp|345|error: no match for 'operator[]' in '*(((Player*)this)->Player::pMap + ((unsigned int)(((unsigned int)((Player*)this)->Player::posx) * 1804u)))[(((Player*)this)->Player::posy + 1)]'|
    C:\Users\Thorbenn\RL\Player.cpp|347|error: no match for 'operator[]' in '*(((Player*)this)->Player::pMap + ((unsigned int)(((unsigned int)((Player*)this)->Player::posx) * 1804u)))[(((Player*)this)->Player::posy + 1)]'|
    ||=== Build finished: 8 errors, 0 warnings ===|
    and here is my code for the function:
    Code:
    void Player::building()
    {
        cout<<"In what direction do you want to build?";
            char secondAction;
            cin>>secondAction;
            switch(secondAction)
            {
            case'w':
            if(pMap[posx-1][posy]==floor && posx !=1 && posx !=mapx-2 && collectedWalls >0)
            {
                pMap[posx-1][posy]=wall;
                collectedWalls--;
    
            }
           //Linux Version
           // system("clear");
    
           //Windows Version
           system("cls");
            pMap->printMap();
            break;
    
            case's':
            if(pMap[posx +1][posy]==floor && posx !=1 && posx !=mapx-2 && collectedWalls >0)
            {
                pMap[posx +1][posy]=wall;
                collectedWalls--;
    
            }
           //Linux Version
           //system("clear");
    
           //Windows Version
           system("cls");
            pMap->printMap();
            break;
    
            case'a':
            if(pMap[posx][posy -1]==floor && posy !=1 && posy !=mapy-4 && collectedWalls >0)
            {
                pMap[posx][posy-1]=wall;
                collectedWalls--;
    
            }
           //Linux Version
           //system("clear");
    
           //Windows Version
           system("cls");
            pMap->printMap();
            break;
    
            case'd':
            if(pMap[posx][posy +1]==floor && posy !=1 && posy !=mapy-4 && collectedWalls >0)
            {
                pMap[posx][posy+1]=wall;
                collectedWalls--;
    
            }
           //Linux Version
           //system("clear");
    
           //Windows Version
           system("cls");
            pMap->printMap();
            break;
    
            }
    }
    Player Class:
    Code:
    class Player
    {
    private:
    
        string name;
        int level;
        int healthMax;
        int health;
        int dexterty;
        int strength;
        int endurance;
        int defense;
        int exp;
        int expMax;
        int pgold;
        int collectedWalls;
        //Player Location
        int posx;
        int posy;
        int x;
        int y;
        Map* pMap;
    
    public:
        //Constructor
        Player();
        //Destructor
       // ~Player();
    
        void newPlayer();
        void levelUp();
        void setHealth(int healthBonus);
        void movement();
        void attack();
        void viewCharacter();
        void building();
        void mineing();
        void setMap(Map* Dungeon);
    
    };
    Map Class:
    Code:
    class Map
    {
    
      public:
      char map[mapx][mapy];
    
      void genMap();
      void printMap();
    
    
    };
    mapx and mapy are constants for all to reach mapx is a int with value of 22 and mapy a integer with value of 88.

    floor, wall or so are also const chars which are reachable for all.

    found my misstake there was always a ->map missing after each pMap[posx][posy -1]

  3. #3
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    That may be the only compile-related problem but there are other problems in that code. It looks like there are many magic numbers and subtractions going on that obfuscate and confuse the very simple idea of checking an array element for a specific value and then performing logic based on the result. You need to look into removing all the magic numbers and fine tune (read: polish) that code.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. building problem, need .h file
    By BadWolf in forum C++ Programming
    Replies: 1
    Last Post: 02-14-2009, 12:12 AM
  2. Having a problem building Zthread
    By indigo0086 in forum Tech Board
    Replies: 1
    Last Post: 04-23-2007, 10:56 AM
  3. Trying to start a roguelike
    By Dark_Oppressor in forum Game Programming
    Replies: 15
    Last Post: 09-22-2006, 05:02 PM
  4. Problem building a Release
    By The SharK in forum C++ Programming
    Replies: 21
    Last Post: 06-23-2006, 05:21 PM
  5. Roguelike Resources
    By Jetlaw in forum Game Programming
    Replies: 3
    Last Post: 04-10-2006, 06:30 AM