[Help] attempt to perform arithmetic on a table value
Posted: Fri Apr 07, 2017 10:21 pm
It seems to error on line 22 in function draw.
Code: Select all
function love.load(arg)
gr = love.graphics
total = 0
objects = {}
amount = 0
end
function love.update(dt)
total = total + dt
for i = 1, #objects do
v = objects[i]
v.x = v.x + v.speed * dt
v.h = math.max(5,v.h + math.sin(total))
v.w = math.max(5,v.w + math.sin(total))
end
end
function love.draw()
for i = 1,#objects do
v = objects[i]
if #objects > 1 and i ~= #objects then
print(objects[i]+1)
b = objects[i]+1
gr.line(v.x,v.y,b.x,b.y)
end
gr.rectangle("fill", v.x, v.y, v.w, v.h)
end
end
function love.keypressed(key, scancode, isrepeat)
if key == "space" then
objects[#objects+1] = newRec()
end
end
function newRec()
object = {}
object.x = gr.getWidth() - gr.getWidth()
object.y = gr.getHeight() * 0.5
object.w = 20
object.h = 20
object.speed = gr.getWidth() / 20
return object
end