Page 1 of 1

A question about writing and appending with love.filesystem

Posted: Thu Feb 15, 2018 5:01 am
by gristly
Hi, first time LOVE user here! I'm just getting into the API so forgive me if the answer here is obvious, but I googled around for a bit to no avail. On the LOVE wiki page for love.filesystem, it says:
Files that are opened for write or append will always be created in the save directory. The same goes for other operations that involve writing to the filesystem, like mkdir.
I'm curious to know if this means LOVE can, in all circumstances, only write to the save directory. Is it completely impossible to write to the source directory (the one containing main.lua)? If so, is there a way to ship a game such that things like config files (which will be modifiable ingame) are automatically placed in the user's save directory on install, or should I just store the initial values for these files in my source directory and then copy them into the save directory if they aren't found there?

Thanks!

Re: A question about writing and appending with love.filesystem

Posted: Thu Feb 15, 2018 9:53 am
by pgimeno
Hello, welcome to the forums!

Once development finishes, the source directory is typically zipped and either renamed to .love or appended to the executable. Saving to that directory would mean to rezip what you save. Löve does not make this possible (it would take a disproportionately big amount of time and I/O to rezip the file, deleting the old version of it and adding the new one, and even more so if it's written dynamically, e.g. with seeks).

You can still use the pure Lua 'io' library instead of love.filesystem, if you want to write elsewhere.

But in the use case you're suggesting, if the config files need some kind of default or template, then yes, it would be best to copy it to your save dir and then modify that one.

Re: A question about writing and appending with love.filesystem

Posted: Thu Feb 15, 2018 10:08 am
by raidho36
It's not like you would want users to be able to screw up the config file without being able to revert to defaults by deleting it, forcing complete re-install if anything goes wrong.

Re: A question about writing and appending with love.filesystem

Posted: Thu Feb 15, 2018 5:21 pm
by gristly
Thanks both of you for your help! More than just an answer, I've gained an understanding :) Stoked to work with love!!