love.filesystem.write() returning as nil?

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.
Post Reply
User avatar
freeve4h
Citizen
Posts: 56
Joined: Sat Apr 30, 2022 9:48 pm
Contact:

love.filesystem.write() returning as nil?

Post by freeve4h »

im making a game, and im trying to program a save system into it

im using

Code: Select all

success = love.filesystem.write( name, data, size )
and

Code: Select all

print(success)
love.filesystem.write("saves/save.txt", "hello") is returning as nil, and the .txt file is blank, is there a way to fix this?
User avatar
GVovkiv
Party member
Posts: 668
Joined: Fri Jan 15, 2021 7:29 am

Re: love.filesystem.write() returning as nil?

Post by GVovkiv »

freeve4h wrote: Tue May 17, 2022 7:50 pm im making a game, and im trying to program a save system into it

im using

Code: Select all

success = love.filesystem.write( name, data, size )
and

Code: Select all

print(success)
love.filesystem.write("saves/save.txt", "hello") is returning as nil, and the .txt file is blank, is there a way to fix this?
From wiki:

Code: Select all

local success, message =love.filesystem.write( filename, "")
if success then 
	print ('file created')
else 
	print ('file not created: '..message)
end
Read what message says.

But my guess is that you trying to write file to non-existing folder.
In that case, "/saves/" which you didn't created.
So maybe to fix your problem you need to create directory where will be file and only then write file:

Code: Select all

love.filesystem.createDirectory("/saves/")
love.filesystem.write("/saves/save.txt", "SSSSSSSS")
User avatar
freeve4h
Citizen
Posts: 56
Joined: Sat Apr 30, 2022 9:48 pm
Contact:

Re: love.filesystem.write() returning as nil?

Post by freeve4h »

GVovkiv wrote: Tue May 17, 2022 8:27 pm
freeve4h wrote: Tue May 17, 2022 7:50 pm im making a game, and im trying to program a save system into it

im using

Code: Select all

success = love.filesystem.write( name, data, size )
and

Code: Select all

print(success)
love.filesystem.write("saves/save.txt", "hello") is returning as nil, and the .txt file is blank, is there a way to fix this?
From wiki:

Code: Select all

local success, message =love.filesystem.write( filename, "")
if success then 
	print ('file created')
else 
	print ('file not created: '..message)
end
Read what message says.

But my guess is that you trying to write file to non-existing folder.
In that case, "/saves/" which you didn't created.
So maybe to fix your problem you need to create directory where will be file and only then write file:

Code: Select all

love.filesystem.createDirectory("/saves/")
love.filesystem.write("/saves/save.txt", "SSSSSSSS")
that helps, but the file still is empty
User avatar
GVovkiv
Party member
Posts: 668
Joined: Fri Jan 15, 2021 7:29 am

Re: love.filesystem.write() returning as nil?

Post by GVovkiv »

freeve4h wrote: Wed May 18, 2022 10:06 am that helps, but the file still is empty
Make sure that you can write data into that folder. (maybe it was set as read-only for some reasons?)
Because for me, on linux system with Fedora and love 11.4 everything works fine:
Screenshot from 2022-05-18 13-17-43.png
Screenshot from 2022-05-18 13-17-43.png (16.16 KiB) Viewed 1874 times

Code: Select all

local data = "test test foo bar"
love.filesystem.createDirectory("/save/")
love.filesystem.write("/saves/save.txt", data)
So it's might be problem in your filesystem somewhere or...
I don't know.
User avatar
freeve4h
Citizen
Posts: 56
Joined: Sat Apr 30, 2022 9:48 pm
Contact:

Re: love.filesystem.write() returning as nil?

Post by freeve4h »

GVovkiv wrote: Wed May 18, 2022 10:19 am
freeve4h wrote: Wed May 18, 2022 10:06 am that helps, but the file still is empty
Make sure that you can write data into that folder. (maybe it was set as read-only for some reasons?)
Because for me, on linux system with Fedora and love 11.4 everything works fine:
Screenshot from 2022-05-18 13-17-43.png

Code: Select all

local data = "test test foo bar"
love.filesystem.createDirectory("/save/")
love.filesystem.write("/saves/save.txt", data)
So it's might be problem in your filesystem somewhere or...
I don't know.
i don't know either. im using windows with love 11.4.
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 53 guests