Writing to files inside game folder

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
Le_juiceBOX
Citizen
Posts: 71
Joined: Sat Mar 26, 2016 3:07 pm

Writing to files inside game folder

Post 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:
SteamLibrary-like Program For Love2D Games:
take me to the forum thread!
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: Writing to files inside game folder

Post by raidho36 »

Yes that's how it works, love can only write in the save directory.
alloyed
Citizen
Posts: 80
Joined: Thu May 28, 2015 8:45 pm
Contact:

Re: Writing to files inside game folder

Post 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
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: Writing to files inside game folder

Post 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.
JaredFuntime
Prole
Posts: 3
Joined: Fri Oct 28, 2016 8:12 pm

Re: Writing to files inside game folder

Post by JaredFuntime »

I think you should look towards this if you want to write files: https://love2d.org/wiki/love.filesystem
Post Reply

Who is online

Users browsing this forum: Bing [Bot], DTmg, Google [Bot] and 3 guests