Page 1 of 1

filesystem.load chunk not calling a function correctly

Posted: Sun Oct 05, 2014 6:37 pm
by moussashi
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:

Code: Select all

-main.lua
-map-functions.lua
-player.lua
-maps/
      -chez-peter.lua
-images/
      -resto.png
main.lua:

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

map-functions.lua:

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
chez-peter.lua

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)


Re: filesystem.load chunk not calling a function correctly

Posted: Sun Oct 05, 2014 7:52 pm
by artofwork
Well whats the exact error?

Upload your love file so we can determine the problem.

Re: filesystem.load chunk not calling a function correctly

Posted: Sun Oct 05, 2014 8:27 pm
by Zilarrezko
well... If you say in the code in map-functions.lua, and say assert(path == nil).

Assert uses it's first parameter as a logical statement(or you can put a variable to check if it's nil or false). If the logical statement is false than assert will throw the error. So... when you use path==nil, it will throw the error if path is not nil. So in your setAssets function, if your 3rd parameter isn't nil, you're going to get an error.

I'm not sure if you wanted to use assert(path ~= nil), where if path is nil then it throws the error.

But as artofwork says. We love .love's, so we can problem solve and test the code more easily, make changes, and when it's all working, tell you how we fixed it, or rather what the problem was.