So I have a "Player.lua" file that returns a function, that creates / returns a class:
player.lua
Code: Select all
function CreatePlayer()
local player={
load=load,
update=update,
draw=draw,
}
setmetatable({},player)
player.__index=player
return player
end
As you see the class has 3 variables, load update and draw. Each of those are defined in the same file as local functions, I thought defining them inside of the player table would get messy. However, inside of those, the only way to manipulate the player's values is to pass the player class table created by that function as an argument, for example -
Code: Select all
var newPlayer=CreatePlayer()
newPlayer.load(newPlayer)
I'm very new to Lua's "classes" and I was wondering if there is a way around this? I've seen people use "self.value" but I'm not sure exactly how that works. I'm betting I have my "Player.lua" set up all wrong. Any help would be very appreciated, I've been looking for an answer for this for a while, but it's kind of difficult to figure out what to look up!