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
newRec creates and returns a table, so all values for all indices of objects is a table;
print(objects[ i ]+1) <-- is the line that errors
objects[ i ] is a table, and you can't add a number to a table, as the error says.
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
zorg wrote: ↑Fri Apr 07, 2017 10:43 pm
newRec creates and returns a table, so all values for all indices of objects is a table;
print(objects[ i ]+1) <-- is the line that errors
objects[ i ] is a table, and you can't add a number to a table, as the error says.
ey thank you. I just noticed what I did wrong. I did it right in some places then of course I would do it wrong there.