Code: Select all
temptable = {}
temptable.x = 710
temptable.y = 20
temptable.width = 40
temptable.height = 30
function love.draw()
local coXX = 100
for i,v in pairs(temptable) do -- if instead we do ipairs then the values of index & key is not showing
love.graphics.setColor(255, 255, 255, 255)
love.graphics.print("value of i : ", 20, 220)
love.graphics.print("value of v : ", 20, 240)
love.graphics.print(i, coXX, 220)
love.graphics.print(v, coXX, 240)
coXX = coXX + 150
end
love.graphics.setColor(255, 100, 50, 255)
love.graphics.rectangle("fill", temptable.x, temptable.y, temptable.width, temptable.height)
end
function love.update(dt)
temptable.x = temptable.x
temptable.y = temptable.y + 10 * dt
end
Now I want to display sub-table values for the following changes in my code :
Code: Select all
temptable = {}
for i=0, 8 do
local box = {}
box.x = 710
box.y = 20
box.width = 40
box.height = 30
table.insert(temptable, box)
end
function love.draw()
local coXX = 100
for i,v in pairs(temptable) do -- if instead we do ipairs then the values of index & key is not showing
love.graphics.setColor(255, 255, 255, 255)
love.graphics.print("value of i : ", 20, 220)
love.graphics.print("value of v : ", 20, 240)
love.graphics.print(i, coXX, 220)
love.graphics.print(v, coXX, 240)
coXX = coXX + 150
end
love.graphics.setColor(255, 100, 50, 255)
for i, v in pairs(temptable) do
love.graphics.rectangle("fill", v.x, v.y, v.width, v.height)
end
end
function love.update(dt)
for i, v in pairs(temptable) do
v.x = v.x
v.y = v.y + 10 * dt
end
end
But the display dont show any values against the keys of the sub-table. given below is the screenshot. Where is the mistake I have done ? Thanks in advance.