title: Using Lua tables as 2-dimensional arrays
body: <p>I'm a beginner Lua user, I attempt to create something in Lua by using Love2D libraries.</p>
  
  <p>In the loading function I create a table and upload it with elements (which are numbers) for use it later as a multidimensional array.</p>
  
  <pre><code>function love.load()
  
      Maximum_X = 32      
      Maximum_Y = 16
  
      Start_X = 64
      Start_Y = 32
  
      MapTable = {}                           -- empty table
  
      for i=1,Maximum_X*Maximum_Y do          -- uploading table
          table.insert(MapTable, 2)
    end
  
  
  end
  </code></pre>
  
  <p>Then I make a function that takes changes in the table. Because I'm just experimenting with tables, there's only one changed value. At least, I thought.</p>
  
  <pre><code>function KatamoriGen()
  
      MapTable[4] = 3     
  
  end
  
  
  function love.update(dt)
  
  KatamoriGen()
  
  end
  </code></pre>
  
  <p>After that, I print the elements of the table in a matrix with 32 coloumns and 16 rows. I see here that not only the 4th element of 1st row is changed, but also the 2nd element of 2nd row and 1st element of 4th row becomes 3. </p>
  
  <p>It obviously means that <code>Table[posX*posY]</code> doesn't work neither since the result of the multiplication is a number like <code>4</code> and the operation would change every elements where </p>
  
  <p><code>X coordinate + Y coordinate = posX*posY</code></p>
  
  <p>is true. In the example code, the right side of this equation was 4.</p>
  
  <p>A small question: why is it happening?</p>
  
  <p>The main question is: how can I identify elements of <code>MapTable</code> exactly? How can I implement X and Y dimensions to Lua tables? to use them as two-dimensional arrays? Maybe table of tables? </p>
  
  <p>EDIT: this is the drawing function:</p>
  
  <pre><code>function love.draw()    
  
  for j=1,16 do
      for i=1,32 do
      love.graphics.draw(Tileset[MapTable[j*Maximum_X + i]], Start_X + 32*(i-1), Start_Y + 32*(j-1))
      end
  end
  
  end
  </code></pre>
  
  <p>Now it's clear for me that this is wrong and the right rule is <code>MapTable[j*Maximum_X + i]</code> but I get an error for it: "expected parameter type: expected userdata"</p>