filesystem.load chunk not calling a function correctly
Posted: Sun Oct 05, 2014 6:37 pm
So right now, I'm trying to modify the code from https://github.com/kikito/love-tile-tutorial/ to organize and reuse it. Inside the file chez-peter.lua, the setAssets() call doesn't seem to send any real values to the imported function in map-functions. I asserted that path == nil, and it always throws an error right there because path is always nil.
The directory looks as such:
main.lua:
map-functions.lua:
chez-peter.lua
The directory looks as such:
Code: Select all
-main.lua
-map-functions.lua
-player.lua
-maps/
-chez-peter.lua
-images/
-resto.png
Code: Select all
------main.lua
require 'map-functions'
require 'player'
function love.load()
updateSV()
love.window.setMode(800,600, {resizable = true})
setMap('maps/chez-peter.lua')
end
--SNIPPED
Code: Select all
---------map-functions.lua--------------
--SNIPPED
local currentPath
maps= {}
function setMap(path)
print(path)
currentPath = path
love.filesystem.load(path)()
end
function setAssets(tw, th, path, quadInfo, tileString, tilesetPath)
assert(path == nil) --ERROR THROWN
maps.path[0] = tw
maps[path].tileH = th
maps[path].tileTable = {}
maps[path].quadInfo = quadInfo
maps[path].tileString = tileString
maps[path].tilesetPath = tilesetPath
end
Code: Select all
package.path = ';../map-functions.lua' .. package.path
require 'map-functions'
local tileString = "map string"
local quadInfo = {
{ ' ', 0, 0 }, -- floor
{ '[', 32, 0 }, -- table top left
{ ']', 64, 0 }, -- table top right
{ '(', 32, 32 }, -- table bottom left
{ ')', 64, 32 }, -- table bottom right
{ 'L', 0, 32 }, -- chair on the left
{ 'R', 96, 32 }, -- chair on the right
{ '#', 96, 0 } -- bricks
}
local tilesetPath = '/images/resto.png'
local path = 'chez-peter.lua'
setAssets(32, 32, path, quadInfo, tileString, tilesetPath)