love 0.9.0 tables
Posted: Sun Jan 05, 2014 5:12 pm
I just got love 0.9.0 and it is amazing! But, I can't use the for i, v in pairs line anymore. Has it been replaced?
Code: Select all
function love.load()
text = "COMMAND:"
block = {}
block.x = 20
block.y = 20
end
function love.textinput(t)
text = text .. t
end
function love.draw()
love.graphics.printf(text, 0, 0, love.graphics.getWidth())
for generator do
love.graphics.rectangle("fill", block[i].x, block[i].y, 10, 10)
end
end
function love.update(dt)
x, y = love.mouse.getPosition()
table.insert(block,{x = x, y = y, dir = dir})
end
Code: Select all
for generator do
Code: Select all
for i,v in ipairs(table) do
-- code
end
Code: Select all
for i,v in pairs(table) do
-- code
end
Code: Select all
temptable = {}
temptable.x = 10
temptable.y = 20
temptable.width = 40
temptable.height = 30
function love.draw()
local coXX = 200
for i,v in pairs(temptable) do
love.graphics.print("value of i : ", 120, 220)
love.graphics.print("value of v : ", 120, 240)
love.graphics.print(i, coXX, 220)
love.graphics.print(v, coXX, 240)
coXX = coXX + 50
end
end
Code: Select all
temptable = {}
temptable.x = 10
temptable.y = 20
temptable.width = 40
temptable.height = 30
function love.draw()
local coXX = 200
for i,v in ipairs(temptable) do
love.graphics.print("value of i : ", 120, 220)
love.graphics.print("value of v : ", 120, 240)
love.graphics.print(i, coXX, 220)
love.graphics.print(v, coXX, 240)
coXX = coXX + 50
end
end
Code: Select all
local tbl = {'these', 'would', 'all', 'be'}
table[5] = 'shown'
table[7] = 'order'
table[6] = 'in'
function love.draw()
for i,v in ipairs(tbl) do
love.graphics.print(v, 0, (i-1)*12)
end
end