File System Problem, Cant write save game.

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.
Chris016
Prole
Posts: 22
Joined: Sat Aug 16, 2008 1:58 am

File System Problem, Cant write save game.

Post 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?
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: File System Problem, Cant write save game.

Post 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())
Chris016
Prole
Posts: 22
Joined: Sat Aug 16, 2008 1:58 am

Re: File System Problem, Cant write save game.

Post 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
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: File System Problem, Cant write save game.

Post 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)
Chris016
Prole
Posts: 22
Joined: Sat Aug 16, 2008 1:58 am

Re: File System Problem, Cant write save game.

Post 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.
User avatar
Flesh Gregor
Prole
Posts: 9
Joined: Thu May 07, 2009 9:30 pm

Re: File System Problem, Cant write save game.

Post 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).
Chris016
Prole
Posts: 22
Joined: Sat Aug 16, 2008 1:58 am

Re: File System Problem, Cant write save game.

Post 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.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: File System Problem, Cant write save game.

Post by bartbes »

Can you guys post stdout.txt and stderr.txt from the installation dir of love (just after running the game)?
User avatar
Flesh Gregor
Prole
Posts: 9
Joined: Thu May 07, 2009 9:30 pm

Re: File System Problem, Cant write save game.

Post 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. :|
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: File System Problem, Cant write save game.

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

Who is online

Users browsing this forum: No registered users and 5 guests