Page 1 of 1

Writing to files inside game folder

Posted: Sun Jun 11, 2017 10:08 pm
by Le_juiceBOX
I am trying to write to a file inside my game folder but instead it is writing to the

%AppData%/LOVE/GameFolder/save.txt

thanks in advance! :awesome:

Re: Writing to files inside game folder

Posted: Mon Jun 12, 2017 12:40 am
by raidho36
Yes that's how it works, love can only write in the save directory.

Re: Writing to files inside game folder

Posted: Mon Jun 12, 2017 1:09 am
by alloyed
here's the sneaky solution: even though love.filesystem only wants to write to the designed save directory, the default lua io functions behave the same way they do in normal lua. this means for example that io.open("file", "w"):write("out\n"):close() will write the the current working directory, and not the save dir. You probably shouldn't ship a game with this but I find it handy for things like in-engine level editors

Re: Writing to files inside game folder

Posted: Mon Jun 12, 2017 1:16 am
by raidho36
You shouldn't do it mainly because doing so requires elevated privileges, which you wouldn't have on any sane system. That's not to mention, default CWD for a video game is normally some unrelated location, so you'd also be shitting up filesystem for no good reason. Finally, that eliminates the issue of people hard-coding file paths which renders software inoperable on many systems, which is a lot more common error than you would imagine.

Re: Writing to files inside game folder

Posted: Fri Jun 30, 2017 10:07 pm
by JaredFuntime
I think you should look towards this if you want to write files: https://love2d.org/wiki/love.filesystem