Saving and loading from love.filesystem 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
QwertyDragon83
Prole
Posts: 2
Joined: Sun May 06, 2018 4:42 am

Saving and loading from love.filesystem directory

Post by QwertyDragon83 »

So before, all the saving and loading I've done has been in a separate folder using the standard Lua IO. However, I couldn't figure out how to make the Lua IO deal with anything other than .txt files. Here's a quick program that generates an image, saves it in the love.filesystem save directory, and fails miserably as it attempts to load such image. "..test/test.png does not exist" So I decided to check if the default directory even exists, and it does. There I found my generated image successfully saved. However, love.filesystem.exists(love.filesystem.getSaveDirectory()) returns nil, so according to love, its own default directory doesn't exist.
I tossed the code into an exe, admin ran it, and got the same result. What good is a save directory if you can't access it again? How can I load the image?

Here's the .lua and .love:
Attachments
main.lua
(971 Bytes) Downloaded 154 times
Astorek86
Prole
Posts: 20
Joined: Fri Jul 13, 2018 7:35 pm

Re: Saving and loading from love.filesystem directory

Post by Astorek86 »

Did you used love.filesystem.setIdentity before using IO-Stuff? If not, than that can be the Problem, because the Behavior of love.filesystem.write, getSaveDirectory etc. can be different...

Try to set the Identity on the very first state of your Game (like, the first line after "function love.load"), maybe that will fix your Problem.
User avatar
zorg
Party member
Posts: 3436
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Saving and loading from love.filesystem directory

Post by zorg »

Or, just use Config Files, and set the identity there.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
pgimeno
Party member
Posts: 3544
Joined: Sun Oct 18, 2015 2:58 pm

Re: Saving and loading from love.filesystem directory

Post by pgimeno »

You should not use getSaveDirectory to save and load files using love.filesystem. To save a file, use love.filesystem.write("filename", ...) and to load it back, use love.filesystem.read("filename", ...)

Explanation: the root directory exposed by love.filesystem is the union of two physical directories, the application's directory and the save directory (the latter takes precedence if there are files named the same). When writing a file to the root dir via love.filesystem, you're actually writing it in your save directory. All LÖVE functions use love.filesystem, therefore they all write to the save directory and read from either the save directory or the application directory.

What love.filesystem.getSaveDirectory does is return the real filesystem path, but you should not be concerned with it when using love.filesystem. It may be sometimes useful for using Lua IO functions or some other functions that require a path in the real filesystem (I don't think there are any in LÖVE but if you use any external libs, or FFI calls, you may need it).
Post Reply

Who is online

Users browsing this forum: No registered users and 51 guests