Hi everyone! I made an utility function for my game to load all of items(which are lua objects/tables) which are located inside {project folder}/Objects/Items.
Here is the code:
local lfs = require "lfs"
local itemsPath = system.pathForFile("Objects/Items", system.ResourceDirectory)
print("This is items path: " .. itemsPath)
inventoryFill = {}
function inventoryFill:fill()
for file in lfs.dir(itemsPath) do
local _, i = string.find(file, "%.")
local moduleName = string.sub(file, 1, i - 1)
if moduleName ~= "" and INVENTORY[moduleName] == nil then
INVENTORY[moduleName] = require("Objects.Items." .. moduleName)
end
for k,v in pairs(INVENTORY) do
print(k .. ' ' .. tostring(v))
end
end
end
return inventoryFill
It works no problem in emulator but when i run it on my android device i get an error:
InventoryFill.lua:5: attempt to concatenate local ‘itemsPath’ (a nil value)
I know that there are some restrictions when it comes working with files on android but what am i missing?