title: Lua: attempt to perform arithmetic on global 'mapfinishes' (a nil value)
body: <p>I'm trying to set up something in a game that runs off of Lua and this specific local function is triggered when the player finishes the map. Here is the code:</p>
  
  <pre><code>local function setDrRanks( ply )
      local name = SQLStr( ply:Nick() )
      local sid = ply:SteamID()
  
      drsql:query( "SELECT MapFinishes from dr_exp WHERE SteamID = '"..sid.."'", function( q, data )
          local row = data[1]
  
          if ( row ) then
              mapfinishes = row["Mapfinishes"]
          end
  
          drsql:query( "REPLACE into dr_exp (`SteamID`, `PlayerName`, `MapFinishes`) VALUES('"..sid.."', "..name..", '"..(mapfinishes+1).."');" );
      end )
  end
  </code></pre>
  
  <p>The function is to insert into SQL via a lua function, which it did successfully when ran the first time, as the player was at 0 finishes. Once they hit 1, it refused to do a simple +1 on the mapfinishes value. Which strange is that this seems to work 100% when the player is at 0 finishes, and it will put them at 1, but once they are at 1, it will not add to it any longer. The error received is:</p>
  
  <pre><code>attempt to perform arithmetic on global 'mapfinishes' (a nil value)
  </code></pre>
  
  <p>Anyone have any ideas? Thanks in advance.</p>