enemies = {}
for i=1,8 do
for j=1,3 do
local enemy = {}
enemy.width = 40
enemy.height = 20
enemy.x = i * (enemy.width + 60) + 100
enemy.y = enemy.height + 100
table.insert(enemies, enemy)
end
end
I don't know, if that's what you intended though. Anyway, the reason why you got nil is that in your version ipairs
return another table that contained three instances of enemy
. For your version to work, you would have to add another ipairs
:
for i,v in ipairs(enemies) do
for _,e in ipairs(v) do
love.graphics.rectangle("fill", e.x, e.y, e.width, e.height)
end
end
Please remember to use local
for function temporaries. And Lua arrays start at 1, not 0.