How can I write to the source directory?

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
Oysi
Prole
Posts: 48
Joined: Fri May 02, 2014 11:18 pm
Location: Earth

How can I write to the source directory?

Post by Oysi »

So say I have my folder. It has main.lua and test.txt, how can I write to that test.txt? I can read from it all nice and well, but I am unable to write to it. The wiki specifically says that the filesystem cannot do that, but I've also tried using io.open, with no luck (but that did work when I ran the lua code on its own, without using love). So how can I do this? The reason I want to do this is because it's just so much simpler to work with. I want to have my settings in the source itself, so I can put it anywhere and transfer it without having to do lots of tedious extra stuff every time.

So just to clarify, I want to overwrite an existing file in the source directory. Which should be pretty straight forward, even across platforms. How can I do this?

EDIT:

io.open gives me "permission denied" error, so I tried to run love with admin and then it worked. But this doesn't seem very nice. I suppose I could set the permission so I can always write, but then I'm back to the tedious bit, especially if I publish it.

Btw, this is on Windows 7.
Follow the potato. Achieve enlightenment.
User avatar
slime
Solid Snayke
Posts: 3132
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: How can I write to the source directory?

Post by slime »

Oysi wrote:io.open gives me "permission denied" error, so I tried to run love with admin and then it worked. But this doesn't seem very nice.
It's a feature of modern operating systems that the program needs special permissions to write to important places. In the grand scheme of things I'd rather it be like that than the alternative. :)

It's also one reason why there's only a single write directory in love.filesystem - there are only a few places that are writable all the time by programs on all operating systems, and of those few only one or two are really meant to be used for writing general program-specific files. LÖVE uses that location.

You could have a button or hotkey in your game/program to open an Explorer window showing the save directory:

Code: Select all

-- This will only work if the save directory actually exists (it gets created the first time a file is written by love.filesystem.)
function OpenSaveDirectory()
    love.system.openURL("file://"..love.filesystem.getSaveDirectory())
end
User avatar
Oysi
Prole
Posts: 48
Joined: Fri May 02, 2014 11:18 pm
Location: Earth

Re: How can I write to the source directory?

Post by Oysi »

Suck it up and deal with it, ok, got it.

=(

Thanks, though. At least now I know.
Follow the potato. Achieve enlightenment.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: How can I write to the source directory?

Post by bartbes »

Oysi wrote:Suck it up and deal with it, ok, got it.
That seems like a misinterpretation of the reply, it's more like "It's possible, but it's extremely painful; if you don't have to, don't."
Post Reply

Who is online

Users browsing this forum: No registered users and 219 guests