Page 1 of 1

Problem with saving files to disk

Posted: Fri Dec 23, 2016 4:29 pm
by reno57
Hi all,
I'm presently working on filesystem, and i have some problems to save data on the disk using the love.filesystem

i made a basic exemple :

Code: Select all

function save()
    	local f = love.filesystem.newFile("test.txt")
    	f:open("w")
	f:write("test")	   
	f:close()	   	
end
When i run the function, everything is ok and i expect a file named test.txt to be created in my "main.lua" directory, but i see absolutely nothing ! :oops:

Someone knows why (i precise i'm working on mac)

Thanks for help.

Re: Problem with saving files to disk

Posted: Fri Dec 23, 2016 4:34 pm
by pedrosgali
It won't save to your project folder but to %appdata%/Love/project Name/test.text. Not sure where it goes on Linux/Mac.

Re: Problem with saving files to disk

Posted: Fri Dec 23, 2016 4:35 pm
by raidho36
It creates file in the savegame folder. Exact location depends on operating system. The filesystem module is designed to work like this. If you need to save to a specific location in the file system, you should use Lua's io library. Because each operating system has its own standard as to where what files should go, you are strongly discouraged form using global paths, and should instead use filesystem module which handles all of this properly.

Re: Problem with saving files to disk

Posted: Fri Dec 23, 2016 4:52 pm
by reno57
I see..., in the wiki they speak about this location :
Mac: /Users/user/Library/Application Support/LOVE
But i didn't find it.
Moreover, i also try to find the file with the file search engine i can't find it also.
I think the file is even not created but i don't know why.

Re: Problem with saving files to disk

Posted: Fri Dec 23, 2016 4:57 pm
by raidho36
Try reading from it. If it's there, you should be able to do it.

Re: Problem with saving files to disk

Posted: Fri Dec 23, 2016 7:44 pm
by zorg
Alternatively, either set the game identity in conf.lua, or call [wiki]love.filesystem.setIdentity[/wiki], since the game not having an identity means it doesn't have a folder it could save data into.

Re: Problem with saving files to disk

Posted: Fri Dec 23, 2016 8:09 pm
by slime
~/Library is hidden by default in newer versions of macOS. You can enter the path (e.g. ~/Library/Application Support/LOVE/) into the Go To Folder popup dialog in Finder (Menu > Go > Go To Folder, or Command-Shift-G).

You can also use [wiki]love.system.openURL[/wiki] to open a Finder window to the save directory from in-game.

Re: Problem with saving files to disk

Posted: Fri Dec 23, 2016 9:07 pm
by reno57
And the winner is SLIME !
Thanks you for the this useful peace of information, indeed i see the file in the directory you mentioned.
Thanks a lot :) subject is closed.

Re: Problem with saving files to disk

Posted: Mon Mar 06, 2017 1:50 am
by timotta
I solved my problem on Android 6 putting this confs on conf.lua:

t.identity = "name_of_my_game"
t.externalstorage = true