Page 1 of 2

File wont save [SLOVED]

Posted: Fri Jun 16, 2023 5:55 pm
by zalander
Hi there,
I have been recently working on a project but i encountered a problem where my file wont save here is the code :

Code: Select all

function love.load()
	--load stuff
end
function love.update()
	-- things
	if love.keyboard.isDown("return") then
            if love.filesystem.getInfo(game.file_n) then
                love.filesystem.write(game.file_n, game.txt)
            else
                love.filesystem.newFile(game.file_n..".lua")
                love.filesystem.write(game.file_n, game.txt)
            end
            love.event.quit()
        end
end
function love.draw()
	--draw stuff
end        

Re: File wont save

Posted: Fri Jun 16, 2023 6:18 pm
by zorg
Did you forget the quotes around "game.txt"? I assume you want that as a filename and not a variable.

Re: File wont save

Posted: Sat Jun 17, 2023 4:10 am
by zalander
zorg wrote: Fri Jun 16, 2023 6:18 pm Did you forget the quotes around "game.txt"? I assume you want that as a filename and not a variable.
No its a variable

Re: File wont save

Posted: Sat Jun 17, 2023 4:32 am
by zalander
I added this to the love.update function and it tells me that the file name is illegal or is insecure

Code: Select all

	if love.keyboard.isDown("return") then
            local success, message = love.filesystem.write(game.file_n, game.txt)
            if success then
                print("File saved successfully!")
            else
                print("Error saving file:", message)
            end
        end

Re: File wont save

Posted: Sat Jun 17, 2023 6:23 am
by Andlac028
What is the content of game.txt? Can you add also print for it?

Re: File wont save

Posted: Sat Jun 17, 2023 8:02 am
by zorg
The naming was a bit confusing, since i assumed the second parameter was the filename when it wasn't;
what's in game.file_n ?

Re: File wont save

Posted: Sat Jun 17, 2023 8:43 am
by zalander
zorg wrote: Sat Jun 17, 2023 8:02 am The naming was a bit confusing, since i assumed the second parameter was the filename when it wasn't;
what's in game.file_n ?
game.file_n contains a string which is the file name

Re: File wont save

Posted: Sat Jun 17, 2023 8:45 am
by zalander
Andlac028 wrote: Sat Jun 17, 2023 6:23 am What is the content of game.txt? Can you add also print for it?
game.txt contains a string

Re: File wont save

Posted: Sat Jun 17, 2023 2:19 pm
by Andlac028
zalander wrote: Sat Jun 17, 2023 4:32 am I added this to the love.update function and it tells me that the file name is illegal or is insecure

Code: Select all

	if love.keyboard.isDown("return") then
            local success, message = love.filesystem.write(game.file_n, game.txt)
            if success then
                print("File saved successfully!")
            else
                print("Error saving file:", message)
            end
        end
And what is the filename?

Re: File wont save

Posted: Sat Jun 17, 2023 5:28 pm
by zalander
Andlac028 wrote: Sat Jun 17, 2023 2:19 pm
zalander wrote: Sat Jun 17, 2023 4:32 am I added this to the love.update function and it tells me that the file name is illegal or is insecure

Code: Select all

	if love.keyboard.isDown("return") then
            local success, message = love.filesystem.write(game.file_n, game.txt)
            if success then
                print("File saved successfully!")
            else
                print("Error saving file:", message)
            end
        end
And what is the filename?
The file name can differ as the user enters it.