Cannot display images from a table
Posted: Fri Mar 10, 2017 1:01 pm
I'm trying to make a 15 tile puzzle game as a way to practice what I've learned about Love2D so far... it's not working out well
tile1 will not display, saying it's attempting to index global value 'tile1' (a nil value). I don't see why the value would be nil.
Sorry if this is a really easy fix, I've been trying for half an hour to no avail and any help will be very appreciated
Code: Select all
require("load")
function love.load()
tile = {}
loc = {}
for i = 1, 15 do --This is where I got desperate, you can ignore it
tile[i] = {img = nil}
end
for i = 1, 15 do
tile[i].img = love.graphics.newImage("assets/tile"..i..".png")
end
for i = 1, 16 do
loc[i] = {x = nil, y = nil}
end
LoadLoc()
background = {
x = 0,
y = 0,
img = love.graphics.newImage("assets/background.png")
}
end
function love.update(dt)
--love.mouse.getX() love.mouse.getY() love.mouse.isDown(1)
end
function love.draw()
love.graphics.draw(tile1.img, loc1.x, loc1.x, 0, 1, 1, 0, 0)
love.graphics.draw(background.img, background.x, background.y, 0, 1, 1, 0, 0)
end
Sorry if this is a really easy fix, I've been trying for half an hour to no avail and any help will be very appreciated