I got error about use undeclared variable when loading map made in Tiled editor.
I use code from @Lerg’s gist to check use of undeclared variables. If I don’t require app.lua file everything is ok. The map is visible in simulator:) but I don’t want give up using app.lua
Relevant part of code is below. I don’t use ‘errorMsg’ variable.
app.lua
if \_M.isSimulator then -- Prevent global missuse local mt = getmetatable(\_G) if mt == nil then mt = {} setmetatable(\_G, mt) end mt.\_\_declared = {} mt.\_\_newindex = function (t, n, v) if not mt.\_\_declared[n] then local w = debug.getinfo(2, 'S').what if w ~= 'main' and w ~= 'C' then error('assign to undeclared variable \'' .. n .. '\'', 2) end mt.\_\_declared[n] = true end rawset(t, n, v) end mt.\_\_index = function (t, n) if not mt.\_\_declared[n] and debug.getinfo(2, 'S').what ~= 'C' then error('variable \'' .. n .. '\' is not declared', 2) end return rawget(t, n) end end
menu.lua
-- Code borrowed from Ponywolf's games local uiData = json.decodeFile( system.pathForFile( "scene/menu/ui/title.json", system.ResourceDirectory ) ) menu = tiled.new( uiData, "scene/menu/ui" ) menu.x, menu.y = display.contentCenterX - menu.designedWidth/2, display.contentCenterY - menu.designedHeight/2