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:
Saving and loading from love.filesystem directory
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
-
- Prole
- Posts: 2
- Joined: Sun May 06, 2018 4:42 am
Saving and loading from love.filesystem directory
- Attachments
-
- main.lua
- (971 Bytes) Downloaded 169 times
Re: Saving and loading from love.filesystem directory
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.
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.
- zorg
- Party member
- Posts: 3465
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: Saving and loading from love.filesystem directory
Or, just use Config Files, and set the identity there.
Me and my stuff True 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.
Re: Saving and loading from love.filesystem directory
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).
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).
Who is online
Users browsing this forum: Bing [Bot] and 3 guests