Page 1 of 3

File System Problem, Cant write save game.

Posted: Fri Jun 12, 2009 5:31 pm
by Chris016
Im trying to write my own game data so that the user can continue his or her own game. But this seems to work but it crashes love with no error or warning. What am i doing wrong.

Code: Select all

SaveGame = love.filesystem.newFile( "Game.txt" )
success = love.filesystem.write(SaveGame, TeamName:getText())

Im using Leif Lib for GUI and TeamName is a input box so im trying to write the teams name in the Game.txt. Any suggestions?

Re: File System Problem, Cant write save game.

Posted: Fri Jun 12, 2009 5:41 pm
by bartbes
You have to open the file first.

Code: Select all

SaveGame = love.filesystem.newFile( "Game.txt" )
love.filesystem.open(SaveGame, love.file_write)
success = love.filesystem.write(SaveGame, TeamName:getText())
Get your hopes up for next version, I just implemented the following syntax in the SVN:

Code: Select all

SaveGame = love.filesystem.newFile( "Game.txt" )
SaveGame:open(love.file_write)
success = Savegame:write(TeamName:getText())

Re: File System Problem, Cant write save game.

Posted: Fri Jun 12, 2009 7:33 pm
by Chris016
Thanks for the help, i got a little farther but hit problem.

Code: Select all

SaveGame = love.filesystem.newFile( "Game.txt",love.file_write )
    love.filesystem.open(SaveGame)
    success = love.filesystem.write(SaveGame, PlayerName:getText())
With that it still crashes. It doesnt write but it doesnt give a error, Just closes game

Re: File System Problem, Cant write save game.

Posted: Fri Jun 12, 2009 8:13 pm
by bartbes
Wait a second.. you don't happen to be running linux, and executing it via the command "love ."?
In that case go up a dir and start love with the name of the dir.
It's a safety feature as it prevents to write to a the following dir /home/user/.love/., as it uses the invoked name as name for the save dir.
(might be vague, just do as I said, problem solved)

Re: File System Problem, Cant write save game.

Posted: Fri Jun 12, 2009 9:51 pm
by Chris016
no im on windows, ive done this on linux and i know about that already :megagrin:

But yea cant lua handle its own file saves, it wont save in the love file but i mean i might have to do that instead.

Re: File System Problem, Cant write save game.

Posted: Fri Jun 12, 2009 10:13 pm
by Flesh Gregor
Just want to chime in and say I'm on windows too and I have the same problem.
If I run

Code: Select all

local SaveGame = love.filesystem.newFile( "save.lua", love.file_write )
assert(love.filesystem.open(SaveGame),love.system.exit())
love.filesystem.write(SaveGame, "yeah")
it exits, so the file's not opening. (I've checked permissions, it's not a problem with that).

Re: File System Problem, Cant write save game.

Posted: Sat Jun 13, 2009 12:36 am
by Chris016
ye, i dont know what it is. Well im thinking of making saved games server side. So then im just going to write the server in C++ and save everything serverside. But it would be nice if the file system would work for me.

Re: File System Problem, Cant write save game.

Posted: Sat Jun 13, 2009 4:57 am
by bartbes
Can you guys post stdout.txt and stderr.txt from the installation dir of love (just after running the game)?

Re: File System Problem, Cant write save game.

Posted: Sat Jun 13, 2009 5:35 am
by Flesh Gregor
When I try to save running the code I posted before, I don't get an stderr.txt (and I don't have an stdout.txt at all). However, if I change it to something like this:

Code: Select all

local SaveGame = love.filesystem.newFile( "save.lua", love.file_write )
assert(love.filesystem.open(SaveGame),assert(print("dammit"),love.system.exit()))
love.filesystem.write(SaveGame, "yeah")
I get this:

Code: Select all

[string "libs/player.lua"]:48: assertion failed!
stack traceback:
[C]: in function 'assert'
[string "libs/player.lua"]:48: in function 'savegame'
[string "libs/player.lua"]:149: in function 'keypressed'
[string "libs/environment.lua"]:55: in function 'keypressed'
[string "main.lua"]:44: in function <[string "main.lua"]:40>
So I guess it has a problem with the print() function, though I don't see how that could help figure out our original problem. I might be mistaken, but I thought print was supposed to be written to stdout.txt, which I don't have. I tried creating a dummy stdout.txt with proper permissions to make sure there wasn't a problem there, but to no avail. :|

Re: File System Problem, Cant write save game.

Posted: Sat Jun 13, 2009 6:51 am
by bartbes
No, it actually says love.filesystem.open failed, and you might need to take a look at the reference manual, correct use of assert is:
assert(function, "OMG CRASED"), it will in turn give you a LÖVE error message with the text "OMG CRASHED" and thereby stop the game.

Stupid of me that I hadn't noticed before but:

Code: Select all

assert(love.filesystem.open(SaveGame),love.system.exit()) --will never work, as it tries to 'evaluate' love.system.exit() before actually checking the return values of love.filesystem.open
So, Chris016, if you can post your stdout.txt and stderr.txt that'd be great.