I am still not getting the need to use self in classes(lua tables).
I know I have global and local variables where local vars only are defined withing thje block. The issue is in a class I can use self or nothing and what is the difference?
The below code works to display an image using self and without self. What is the differnce as it both works globally within the class which is what I want?
module(…, package.seeall)
player = {}
player.__index = player
function player:new(i)
local o = {};
o._i = i;
setmetatable(o,self)
self:loadimages();
return o;
end
img1= display.newImage(“ship1c.png”) – this works
function player:loadimages()
self.img2= display.newImage(“ship1c.png”) --this works as well
self.img2.x=100;
img1.x=200;
end
function player:setPosition(x)
self.img2.x=self.img2.x + x;
img1.x=img1.x+x;
end [import]uid: 138547 topic_id: 25040 reply_id: 325040[/import]