I receive the following:
Code: Select all
Error
menu.lua:8: attempt to index field 'newBox' (a nil value)
Traceback
menu.lua:8: in function 'create'
main.lua:6: in function 'load'
[C]: in function 'xpcall'
Code: Select all
require "menu"
require "box"
function love.load()
newMenu = Menu:create()
end
function love.update(delta)
end
function love.draw()
newMenu:draw()
end
Code: Select all
Menu = {}
Menu.__index = Menu
function Menu:create()
local menu = {}
setmetatable(menu, Menu)
menu.newBox:create(100, 100, 100, 50)
return menu
end
function Menu:draw()
self.newBox:draw()
end
Code: Select all
Box = {}
Box.__index = Box
function Box:create(x, y, width, height)
local box = {}
setmetatable(box, Box)
box.x = x
box.y = y
box.width = width
box.height = height
return box
end
function Box:draw()
love.graphics.rectangle("fill", self.x, self.y, self.width, self.height)
end
function Box:getX()
return self.x
end
function Box:getY()
return self.y
end
function Box:setX(x)
self.x = x
end
function Box:setY(y)
self.y = y
end