title: How can I call a class function inside a class using middleclass in Lua
body: <p>I've been trying to figure out how to call a class function inside another class function in Lua, but the way I thought would work doesn't.</p>
  
  <pre><code>local class = require 'libs.middleclass'
  
  local Level = class('Level')
  
  function Level:initialize(width, height, tileSize)
      self.width = width
      self.height = height
      self.tileSize = tileSize
      self.data = {}
      --Generate a 1D Array for the map data
      for x = 1, self.width do
          for y = 1, self.height do
              table.insert(self.data, 0)
          end
      end
  end
  
  function Level:get(x, y)
      return self.data[x + (y-1) * self.width]
  end
  
  function Level:set(x, y, type)
      self.data[x + (y - 1) * self.width] = type
  end
  
  function Level:draw()
      for x = 1, self.width do
          for y = 1, self.height do
              if self.Level:get(x, y) == 0 then
                  love.graphics.setColor(255, 255, 255)
                  love.graphics.rectangle("fill", x * tileSize, y * tileSize, tileSize, tileSize)
                  love.graphics.setColor(0, 0, 0)
                  love.graphics.rectangle("line", x * tileSize, y * tileSize, tileSize, tileSize)
              elseif self.Level:get(x, y) == 1 then
                  love.graphics.setColor(255, 255, 255)
                  love.graphics.rectangle("fill", x * tileSize, y * tileSize, tileSize, tileSize)
              end 
          end
      end
  end
  
  return Level
  </code></pre>
  
  <p>Not sure if you need all of the code, but this is what I have in my level.lua object class thingy. I thought that calling it using self.method would work, but it gives me:</p>
  
  <pre><code>objects/level.lua:29: attempt to index field 'Level' (a nil value)
  </code></pre>
  
  <p>That's about all I can say about it since I'm new to doing OOP in Lua, also I'm using the Love2D framework if that is in any way relevant.</p>
  
  <p>Thanks for taking your time to answer.</p>