Problem with saving files to disk

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
reno57
Prole
Posts: 17
Joined: Thu Apr 14, 2016 9:46 pm

Problem with saving files to disk

Post 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.
pedrosgali
Party member
Posts: 107
Joined: Wed Oct 15, 2014 5:00 pm
Location: Yorkshire, England

Re: Problem with saving files to disk

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

Code: Select all

if not wearTheseGlasses() then
  chewing_on_trashcan = true
end
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: Problem with saving files to disk

Post 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.
reno57
Prole
Posts: 17
Joined: Thu Apr 14, 2016 9:46 pm

Re: Problem with saving files to disk

Post 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.
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: Problem with saving files to disk

Post by raidho36 »

Try reading from it. If it's there, you should be able to do it.
User avatar
zorg
Party member
Posts: 3436
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Problem with saving files to disk

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

Re: Problem with saving files to disk

Post 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.
reno57
Prole
Posts: 17
Joined: Thu Apr 14, 2016 9:46 pm

Re: Problem with saving files to disk

Post 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.
timotta
Prole
Posts: 3
Joined: Sun Dec 18, 2016 1:42 pm
Contact:

Re: Problem with saving files to disk

Post by timotta »

I solved my problem on Android 6 putting this confs on conf.lua:

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

Who is online

Users browsing this forum: No registered users and 53 guests