Problem with LFS

The game crashes on the phone, but everything is fine in Corona Simulator

local function preloadImage(fileDirectory, fileName, tableToInsert)
    local texture = graphics.newTexture({
        type = "image",
        filename = string.format("%s/%s", fileDirectory, fileName),
        baseDir = system.ResourceDirectory
    })
    texture:preload()
    tableToInsert[fileName] = texture
end

local lfs = require("lfs")
for _,value in ipairs(toLoad.character) do
    local oldPath = string.format("%s%s", texturesFolder, value)
    local path = system.pathForFile(oldPath, system.ResourceDirectory)
    loaded.character[value] = {}
    local array = loaded.character[value]
    for file in lfs.dir(path) do
        if string.find(file, ".png") then
            preloadImage(oldPath, file, array)
        end
    end
end

Android apps are archives. They can’t be traversed like regular folders because they don’t have such.

One work-around is to create a list of the files you want to go through while you’re on the simulator and then just iterate through the list when on running the app on a real device.

okay thank you

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.