I am trying to write a game that saves data to a folder.
My issues:
+love.filesystem.createDirectory does not work
+love.filesystem.setIdentity does not work
+love.filesystem.isDirectory does not work
+I can't just save to something like: "maps/"..file Is that supposed to work, or not?
If someone could give an example on how to save to a folder, that'd be nice!
Thank you - all help is appreciated.
Saving to Folders Issues
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- MicroMacro
- Citizen
- Posts: 92
- Joined: Fri May 30, 2014 2:30 am
- Location: Boston, MA, USA
- Contact:
Saving to Folders Issues
https://github.com/ebernerd- where you can find all my work.
Re: Saving to Folders Issues
I have to admit that I'm not too familiar with the Love2D filesystem module.
But generally it's not a good idea to save data anywhere on the disk.
If you're a "guest user" on some Windows systems you may not have permission to write in certain directories.
Usually, you want to save to "love.filesystem.getAppdataDirectory"
Also, depending on the implementation it may not be possible to create nested folders like:
"C:/non-existent1/non-existent2/non-existent3/"
So you may have to create the folders one after another: "non-existent-1", "non-existent-2" and "non-existent-3"
Hope this helps
But generally it's not a good idea to save data anywhere on the disk.
If you're a "guest user" on some Windows systems you may not have permission to write in certain directories.
Usually, you want to save to "love.filesystem.getAppdataDirectory"
Also, depending on the implementation it may not be possible to create nested folders like:
"C:/non-existent1/non-existent2/non-existent3/"
So you may have to create the folders one after another: "non-existent-1", "non-existent-2" and "non-existent-3"
Hope this helps
Re: Saving to Folders Issues
With the filesystem module you aren't supposed to deal with full paths. love.filesystem is always relative to the LÖVE save directory.ivan wrote:I have to admit that I'm not too familiar with the Love2D filesystem module.
But generally it's not a good idea to save data anywhere on the disk.
If you're a "guest user" on some Windows systems you may not have permission to write in certain directories.
Usually, you want to save to "love.filesystem.getAppdataDirectory"
Also, depending on the implementation it may not be possible to create nested folders like:
"C:/non-existent1/non-existent2/non-existent3/"
So you may have to create the folders one after another: "non-existent-1", "non-existent-2" and "non-existent-3"
Hope this helps
Did you call love.filesystem.setIdentity before you did anything else? What does "love.filesystem.setIdentity doesn't work" mean?
- MicroMacro
- Citizen
- Posts: 92
- Joined: Fri May 30, 2014 2:30 am
- Location: Boston, MA, USA
- Contact:
Re: Saving to Folders Issues
Whenever I did the setIdentity, it never actually switched the identity. I used a print-toconsole debug test to see what the identity was, but it was the same as before.
https://github.com/ebernerd- where you can find all my work.
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Saving to Folders Issues
Yeah we still can't help you without a .love. Other LÖVE games work for you, right?
Help us help you: attach a .love.
- MicroMacro
- Citizen
- Posts: 92
- Joined: Fri May 30, 2014 2:30 am
- Location: Boston, MA, USA
- Contact:
Re: Saving to Folders Issues
I don't feel comfortable releasing a whole love file, this project is kinda secret-ish.
Here's the code I'm having trouble with:
Here's the code I'm having trouble with:
Code: Select all
function editor.saveMap(file)
saveTo = ("maps/"..file)
local defaultIdentity = love.filesystem.getIdentity()
love.filesystem.setIdentity(saveTo)
table.save(editor.tileXs,saveTo.."xs")
table.save(editor.tileYs,saveTo.."ys")
table.save(editor.tileIDs,saveTo.."ids")
love.filesystem.setIdentity(defaultIdentity)
end
https://github.com/ebernerd- where you can find all my work.
Re: Saving to Folders Issues
It doesn't work because that's not what setIdentity does. Identity is meant to be just a string (without any relation to folders etc. - a plain string that is filenamesave and w/o punctuation) that identifies your project. All the file and directory stuff you deal with in the other functions, and all the paths are automatically relative to SOME_MAGICAL_DIR/<identity> where SOME_MAGICAL_DIR is carefully selected for you in a cross-platform way.MicroMacro wrote:I don't feel comfortable releasing a whole love file, this project is kinda secret-ish.
Here's the code I'm having trouble with:Code: Select all
function editor.saveMap(file) saveTo = ("maps/"..file) local defaultIdentity = love.filesystem.getIdentity() love.filesystem.setIdentity(saveTo) table.save(editor.tileXs,saveTo.."xs") table.save(editor.tileYs,saveTo.."ys") table.save(editor.tileIDs,saveTo.."ids") love.filesystem.setIdentity(defaultIdentity) end
Your exact abuse is actually kind of shown in the Example on the setIdentity wiki page: https://www.love2d.org/wiki/love.filesystem.setIdentity
- MicroMacro
- Citizen
- Posts: 92
- Joined: Fri May 30, 2014 2:30 am
- Location: Boston, MA, USA
- Contact:
Re: Saving to Folders Issues
Well, sorry to say, but the Wiki and your help has not worked so far. I would appreciate it if someone could produce a simple, working example to base my own code off of. Thank you in advance for the help.
https://github.com/ebernerd- where you can find all my work.
- slime
- Solid Snayke
- Posts: 3132
- Joined: Mon Aug 23, 2010 6:45 am
- Location: Nova Scotia, Canada
- Contact:
Re: Saving to Folders Issues
Assuming your custom table.save function uses love.filesystem.write (or a File object and File:write):
Code: Select all
function editor.saveMap(file)
local saveTo = "maps/"..file
table.save(editor.tileXs,saveTo.."xs")
table.save(editor.tileYs,saveTo.."ys")
table.save(editor.tileIDs,saveTo.."ids")
end
Who is online
Users browsing this forum: No registered users and 155 guests