First, a tip: Posting english code snippets amounts for faster/better help.
Now, onto the issues: (from smaller to bigger)
- anything = nil will only ever be a placeholder, it doesn't make sense to have it, unless you want a visual reminder of those variables.
- Same with someTable.somefield = nil
- You don't -technically- need to initialize the inner tables to 0, only those that hold tables themselves, but you might have a good reason to do it anyway.
- Why are you setting Tabuleiro.x and y to 5 every update?
- love.graphics.draw draws an image on the screen, it has no return value. You'd either want to store images in the table slots, or some other data that can tell the drawing code what to draw in love.draw. I'm guessing you want to do the latter.
So, here's a bit of a rewrite; not saying it'll work, i haven't tested it myself, but it should show how things would work more correctly.
Code: Select all
-- Use locals, then it makes sense to have nil variables.
local Tabuleiro = {}
local vazio -- don't even need the explicit "= nil" written out! :3
local casax, casay = 0,0;
local Piece1 = {x = 0, y = 0, img = nil}
function IniciaTabuleiro()
for i = 1, 10 do
Tabuleiro[i] = {}
-- As long as Tabuleiro[i][j] is not a table you'd accidentally index into, you don't need to initialize it.
-- But since you have an empty image...
Tabuleiro[i][j] = vazio
end
end
function love.load(args)
vazio = love.graphics.newImage('vazio.png') -- Salva img na memoria
Piece1.img = love.graphics.newImage('aviao1.png')
IniciaTabuleiro()
Tabuleiro[2][3] = Piece1.img
end
function love.update(dt)
if love.keyboard.isDown('escape') then
love.event.push('quit') -- Fecha quando aperta ESC
end
end
function love.draw(dt)
for x = 1, #Tabuleiro do -- This way you get the max number from the table itself.
for y = 1, #Tabuleiro[x] do -- Same here
love.graphics.draw(Tabuleiro[x][y], (y-1) * 50, (x-1) * 50) -- Desenha o tabuleiro
end
end
end