You probably don't want to abuse the variable "self" like that, since you'll end up heavily shadowing it with other object-oriented code.
Instead, define your player class like so:
Code: Select all
Player = {}
Player.__index = Player
function Player.new(filename,x,y)
local self = {
placement = {
x = x,
y = y
},
image = {
body = love.graphics.newImage(filename)
}
}
self.image.width = self.image.body:getWidth()
self.image.height = self.image.body:getHeight()
return setmetatable(self, Player)
end
function Player:doSomething()
-- example of defining a class function for the objects to use
end
player = Player.new("player.png", 0, 0)
player:doSomething()
The important parts of this are: self is local to the function, not global. Player, with a capital P, is that table where you can define functions for the player object. player, with a lowercase p, is the global object that you'll interact with.
This is the bare minimum basic class system for lua, which doesn't require a framework, and should cover most of your needs.
Also, I recommend this to everyone, please read the free ebook
Programming Lua.