function Me.new(tx,ty)
table.insert(Me,{Img=love.graphics.newImage("love_ball.png");
x=tx;
y=ty})
end
function load()
Me:new(200,200)
Me:new(70,500)
Me:new(200,400)
end
--declare the variable before trying to use it
images = {}
function loadImages()
--load images only once
loveball = love.graphics.newImage("images/love-ball.png")
end
function newImage(tx,ty)
--use the image reference
table.insert(images, {img=loveball; x=tx; y=ty})
end
function load()
loadImages()
newImage(200,200)
newImage(70,500)
newImage(200,400)
--print stuff into log (check the stdout.txt)
for key, value in ipairs(images) do
print(key .. " " .. value.x .. " " .. value.y)
end
end
function draw()
--draw images
for key, value in ipairs(images) do
love.graphics.draw(value.img, value.x, value.y)
end
end
Neolitik: the table:func() notation uses an implicit self, and is equivalent to table.func(self). However, you are using it inconsistently: in the function declaration, you use . but every function call you use :
In this case, you're not using the self argument, so you can either change it to
function Me.new(tx,ty)
table.insert(Me,{Img=love.graphics.newImage("love_ball.png");
x=tx;
y=ty})
end
function load()
Me.new(200,200)
Me.new(70,500)
Me.new(200,400)
end
function Me:new(tx,ty)
table.insert(self,{Img=love.graphics.newImage("love_ball.png");
x=tx;
y=ty})
end
function load()
Me:new(200,200)
Me:new(70,500)
Me:new(200,400)
end