Main.lua not recognizing a function. [SOLVED]
Posted: Sun Jun 08, 2014 9:53 pm
I'm having a problem where a certain function in my main.lua is simply not being recognized, or something of the sort.
The error that I'm getting is:
main.lua:18: attempt to call field 'draw' (a nil value)
from what I understand, that means that for some reason main.lua thinks that a function called map.draw() doesn't exist, right?
Here's my code.
main.lua
map.lua
What really confuses me is that my player.lua works just fine, loads and draws correctly. And if I put map.lua in a separate project and run it on it's own, it works. It's just the linking between main and map that's the problem. I'm completely stumped, I feel that I'm missing something really obvious or I've just made a stupid mistake, hopefully somebody can help me out here.
The error that I'm getting is:
main.lua:18: attempt to call field 'draw' (a nil value)
from what I understand, that means that for some reason main.lua thinks that a function called map.draw() doesn't exist, right?
Here's my code.
main.lua
Code: Select all
require "map"
require "player"
function love.load()
window = love.window.setMode(640, 480)
player.load()
map.load()
end
function love.update(dt)
player.update(dt)
--map.update(dt)
end
function love.draw()
player.draw()
map.draw()
end
Code: Select all
map = {}
function map.load()
map = {
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1},
{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
{1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1},
{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
{1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
}
map.mapWidth = #map[1]
map.mapHeight = #map
map.tileWidth = 32
map.tileHeight = 32
end
function drawMap()
for y = 1, map.mapHeight do
for x = 1, map.mapwidth do
if map[y][x] == 1 then
love.graphics.setColor(255, 255, 0)
love.graphics.rectangle("fill", (x-1)*map.tileWidth, (y-1)*map.tileHeight, map.tileWidth, map.tileHeight)
end
end
end
end
function map.draw()
drawMap()
end