Code that caused error, "index global grid a nil value"
Code: Select all
function love.load()
gridYCount = 4
gridXCount = 4
function move(direction)
for y = 1, gridYCount do
for x = 1, gridXCount do
if grid[y][x] == gridXCount * gridYCount then
emptyX = x
emptyY = y
end
end
end
-- establishing grid
grid = {}
for y = 1, gridYCount do
grid[y] = {}
for x = 1, gridXCount do
grid[y][x] = x + ((y - 1) * gridXCount)
end
end
end
Code: Select all
function love.load()
gridYCount = 4
gridXCount = 4
-- establishing grid
grid = {}
for y = 1, gridYCount do
grid[y] = {}
for x = 1, gridXCount do
grid[y][x] = x + ((y - 1) * gridXCount)
end
end
function move(direction)
for y = 1, gridYCount do
for x = 1, gridXCount do
if grid[y][x] == gridXCount * gridYCount then
emptyX = x
emptyY = y
end
end
end
end
The conceptual model (i.e knowledge) I gained during studying the fundamentals of programming is that functions are not executed unless they are called, The error arised immediately after running Love2D file. Could someone explain this to me?