Saving to Folders Issues

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.
User avatar
MicroMacro
Citizen
Posts: 92
Joined: Fri May 30, 2014 2:30 am
Location: Boston, MA, USA
Contact:

Saving to Folders Issues

Post by MicroMacro »

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.
https://github.com/ebernerd- where you can find all my work.
User avatar
ivan
Party member
Posts: 1911
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: Saving to Folders Issues

Post by ivan »

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
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Saving to Folders Issues

Post by Robin »

Could you upload a .love?
Help us help you: attach a .love.
User avatar
s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

Re: Saving to Folders Issues

Post by s-ol »

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
With the filesystem module you aren't supposed to deal with full paths. love.filesystem is always relative to the LÖVE save directory.

Did you call love.filesystem.setIdentity before you did anything else? What does "love.filesystem.setIdentity doesn't work" mean?

s-ol.nu /blog  -  p.s-ol.be /st8.lua  -  g.s-ol.be /gtglg /curcur

Code: Select all

print( type(love) )
if false then
  baby:hurt(me)
end
User avatar
MicroMacro
Citizen
Posts: 92
Joined: Fri May 30, 2014 2:30 am
Location: Boston, MA, USA
Contact:

Re: Saving to Folders Issues

Post by MicroMacro »

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.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Saving to Folders Issues

Post by Robin »

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.
User avatar
MicroMacro
Citizen
Posts: 92
Joined: Fri May 30, 2014 2:30 am
Location: Boston, MA, USA
Contact:

Re: Saving to Folders Issues

Post by MicroMacro »

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
https://github.com/ebernerd- where you can find all my work.
User avatar
s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

Re: Saving to Folders Issues

Post by s-ol »

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
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.

Your exact abuse is actually kind of shown in the Example on the setIdentity wiki page: https://www.love2d.org/wiki/love.filesystem.setIdentity

s-ol.nu /blog  -  p.s-ol.be /st8.lua  -  g.s-ol.be /gtglg /curcur

Code: Select all

print( type(love) )
if false then
  baby:hurt(me)
end
User avatar
MicroMacro
Citizen
Posts: 92
Joined: Fri May 30, 2014 2:30 am
Location: Boston, MA, USA
Contact:

Re: Saving to Folders Issues

Post by MicroMacro »

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.
User avatar
slime
Solid Snayke
Posts: 3132
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Saving to Folders Issues

Post by slime »

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
Post Reply

Who is online

Users browsing this forum: No registered users and 155 guests