Page 1 of 1

[solved] why does love.filesystem.getInfo return nil on a file that is definitely there?

Posted: Sun Nov 05, 2023 8:13 am
by MWTab
Hiya,

I'm writing a love2d starter template for blind accessible games, and I just got my screen reader c library working from within the .love file by copying it to the save directory... However:

I tried to make the template only copy the file(s) if they weren't already there, but that doesn't seem to be working. I do some code like this:

Code: Select all

        if love.filesystem.getInfo(love.filesystem.getSaveDirectory() .. "/" ..
                                       libName) == nil then -- The file doesn't exist, we need to copy it
            -- Fixme, probably should do sanity checks like size, etc, but this will do for now.
            print(love.filesystem.getSaveDirectory() .. "/" .. libName ..
                      " not found...")
            local content = love.filesystem.read(libName)
            love.filesystem.write(libName, content)
        end
        
However, even after the first time of copying the library, getInfo still returns nil, causing it to be copied on every startup. Any idea why this might be? Maybe it doesn't like me using a full path or... something?

Thanks,

-Michael.

P.S. If you want to see the whole project go here: https://git.2mb.codes/~lilmike/love2d-template

Re: why does love.filesystem.getInfo return nil on a file that is definitely there?

Posted: Sun Nov 05, 2023 1:12 pm
by BrotSagtMist
Löve was not made for users to deal with files manually.
If you want to defeat the two folders seen as one structure by using relative paths you will just end up with the worst mess of code.

A far easier solution is to simply not use the same name or place for the file.

Re: why does love.filesystem.getInfo return nil on a file that is definitely there?

Posted: Sun Nov 05, 2023 2:57 pm
by MWTab
Ok, I will try that.

-Michael.

Re: why does love.filesystem.getInfo return nil on a file that is definitely there?

Posted: Sun Nov 05, 2023 5:07 pm
by MWTab
That worked like a charm. Moved my shared libraries under a subdirectory in my .love file and copied them with no subdirectory :-).

-Michael.

Re: why does love.filesystem.getInfo return nil on a file that is definitely there?

Posted: Sun Nov 05, 2023 9:01 pm
by slime
The reason it returned nil in your code is getInfo (and almost every other love.filesystem API) doesn't take full paths, only relative ones. All relative paths in love.filesystem are relative to both the game's source and save directories.

Another way to achieve what you want could be to check what love.filesystem.getRealDirectory returns for the library file, if it has the same relative path in the source and save directories.

Re: why does love.filesystem.getInfo return nil on a file that is definitely there?

Posted: Sun Nov 05, 2023 9:21 pm
by MWTab
Thanks for the pointers. I believe I've solved it ok now, and it even makes my git repo a bit cleaner :D but I'll definitely keep your tips in mind for future use :-).

Btw, is there a way to mark this topic solved?

-Michael.

Re: why does love.filesystem.getInfo return nil on a file that is definitely there?

Posted: Mon Nov 06, 2023 7:33 am
by pgimeno
MWTab wrote: Sun Nov 05, 2023 9:21 pm Btw, is there a way to mark this topic solved?
By editing the first post and changing the topic.