title: C++ object not saving variable values
body: <p>I am a beginner C++ programmer, self-taught. I am developing a simple roguelike game as a learning project. The problem I'm having is in the code used to determine if the player is able to move in the specified direction. When the player wants to move one square east for example, the following code is run, where int a and b are the <strong>intended</strong> square's X and Y coordinates:</p>
  
  <pre><code>bool Location::canMove(int a, int b)
  {
      for (int i = 0; i &lt; Decorations.size(); i++)
      {
          if (Decorations[i].getPosX() == b &amp;&amp; Decorations[i].getPosY() == a)
          {
              Match = true;
              Matched = Decorations[i];
              break;
          } else
          {
              Match = false;
          }
      }
  
      if (Match == true)
      {
          if (Matched.Clips() == true)
          {
              Blocked = true;
              return false;
          } else
          {
              Blocked = false;
              return true;
          }
      } else
      {
  
          switch(Map[a][b])
          {
              case TILE_VOID:
              case TILE_FLOOR:
              Blocked = false;
              return true;
              break;
          case TILE_WALL:
              Blocked = true;
              return false;
              break;
          }
      }
  }
  </code></pre>
  
  <p>Essentially what it does is sees if the player's current location has any Decorative objects at those X and Y coordinates, like tables, pillars etc. If it finds it has one, it then runs a check to see if that object allows a player to pass through it or not with the Clips() function and returns true or false to determine if the player can move there. If no decoration object is found, it then checks the base tile of that location, if it's void or floor then the player can move, if it's a wall then they can't.</p>
  
  <p>This piece of code works fine as far as I can tell (the player isn't able to move through walls or solid objects). However, in the main loop there is another function that is called if the player is told they cannot move, which informs the player why:</p>
  
  <pre><code>string Location::blockMsg()
  {
      blockmsg = "You bump into the ";
      if (Blocked == false)
      {
          blockmsg = blockmsg + "wall";
      } else
      {
          blockmsg = blockmsg + Matched.getName();
      }
      return blockmsg;
  
  }
  </code></pre>
  
  <p>This is used to inform the player why they couldn't move in that direction. If they bumped into a table it should say "You bump into the table", for example.</p>
  
  <p>The problem I'm having is that it doesn't look like the bool Matched or Blocked, or the decoration Matched are being saved once the first piece of code finishes. As such, the logic always acts as though Blocked == false, even if the player has bumped into a decoration that blocks their movement. The result is that if a player is blocked by something, it will always say "You bump into the wall" even if it's something else.</p>
  
  <p>The only assumption I can make is that for some reason, when assigning Blocked = true in the first function, it's not retained for whatever reason for the next function to use it.</p>
  
  <p>Can anyone point out where I've gone wrong? I always assumed that once a Location's Match, Matched and Blocked values are set during the canMove() function, they should retain those same values for blockMsg() to use, but apparently not.</p>