I'm trying to create a class for my game and I got this error (shown in love2d): attempt to index upvalue 'World' (a boolean value)
This is my World file I made:
local World = {}
World.__index = World
function World:new(meter, gravity)
setmetatable({}, World)
-- Set physics parameters
love.physics.setMeter(meter)
self.world = love.physics.newWorld(0, gravity*meter, true)
-- Load background
self.background = love.graphics.newImage("imgs/background.png")
return self
end
function World:update(dt)
end
function World:draw()
love.graphics.draw(self.background)
end
function World:destroy()
-- Destroy the world
self.world:destroy()
end
And here I call the world:
local World = require("world")
function love.load()
-- Build the world
world = World:new(32, 9.81)
end
What is wrong? Anyway, what is the best way for make a class in Lua?