Page 1 of 2
Help with filesystem?
Posted: Sun Nov 23, 2014 7:27 pm
by natev
I know this is dumb, but...
How can I most simply create a text file if it doesn't exist, then append a line of text, then close it?
I'm trying to create simple output to a textfile (for debugging purposes, mostly). I would like to have something like,
Code: Select all
i, emergencyBrake = 0, 10^10
while table.continue do
i = i +1
...
if i==emergencyBrake then debug:log("logfile.txt", "Loop went on too long, table contains "..debug:dump(table)); break end
end
Lua io.write() isn't creating a new file (like I've read it is supposed to?). love.filesystem.newFile() isn't creating a file anywhere (although love.filesystem.createDirectory() is creating a directory in my user folder), and, in any case, it looks like the love filesystem is tuned for streams and such rather than what I want to do (data:new()?)
Any help would be greatly appreciated!
Re: Help with filesystem?
Posted: Mon Nov 24, 2014 7:34 am
by s-ol
love.filesystem.write automatically creates a file if needed:
Code: Select all
local str = "blergh blergh blergh"
if love.filesystem.isFile( "sometime.txt" ) then
str = love.filesystem.read( "sometime.txt" ) .." \n".. str
end
love.filesystem.write( "somefile.txt", str )
Re: Help with filesystem?
Posted: Mon Nov 24, 2014 8:00 pm
by natev
Thank you very much, that's working great!
Re: Help with filesystem?
Posted: Wed Dec 03, 2014 11:08 am
by Robin
That is really bad, especially if you write often and if the file grows large.
Use [wiki]love.graphics.append[/wiki]("logfile.txt", "This is a line in the log") instead.
Re: Help with filesystem?
Posted: Wed Dec 03, 2014 11:57 am
by kikito
Robin wrote:That is really bad, especially if you write often and if the file grows large.
Use [wiki]love.graphics.append[/wiki]("logfile.txt", "This is a line in the log") instead.
Robin clearly meant
filesystem instead of
graphics there:
[wiki]love.filesystem.append[/wiki]("logfile.txt", "This is a line in the log")
Re: Help with filesystem?
Posted: Wed Dec 03, 2014 12:24 pm
by Azhukar
kikito wrote:Robin clearly meant filesystem instead of graphics there
I must admit that was pretty funny.
Re: Help with filesystem?
Posted: Wed Dec 03, 2014 12:51 pm
by Robin
What. Kikito is right. That's one weird brain fart.
Re: Help with filesystem?
Posted: Fri Dec 12, 2014 6:31 pm
by Doctory
Robin wrote:What. Kikito is right. That's one weird brain fart.
this happens way too often to me
Re: Help with filesystem?
Posted: Sat Dec 13, 2014 11:39 am
by bartbes
For some reason, every time I attribute a function to the wrong module, it's always to love.graphics. I guess it's just the module I type the name of most often.
Re: Help with filesystem?
Posted: Sat Dec 13, 2014 5:33 pm
by undef
It's also a common typo for me to write love.graphics.
That, and loval instead of local...