Can't start new lines with love.filesystem?

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.
FishofMuu
Prole
Posts: 3
Joined: Fri Mar 18, 2011 9:42 pm

Can't start new lines with love.filesystem?

Post by FishofMuu »

Okay, this has been really bugging me for like an hour now.

Code: Select all

file = love.filesystem.newFile("test.txt")
file:open('a')
stringy = ""
stringy = stringy.."one\n"
stringy = stringy.."\ntwo"
stringy = stringy.."three"
stringy = stringy.."\n"
stringy = stringy.."four"
file:write(stringy)
print(stringy)
This will get me a file with "onetwothreefour" all on one line. The console will get it separated into different lines.

If I do:

Code: Select all

file = love.filesystem.newFile("test.txt")
file:open('a')
file:write("one\n")
file:write("\ntwo")
file:write("three")
file:write("\n")
file:write("four")
I again get "onetwothreefour". Obviously, love.filesystem ignores \n. So... I guess the question is how do I start a new line in a file?
User avatar
slime
Solid Snayke
Posts: 3166
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Can't start new lines with love.filesystem?

Post by slime »

Have you tried \r or \r\n? (wild guess)
FishofMuu
Prole
Posts: 3
Joined: Fri Mar 18, 2011 9:42 pm

Re: Can't start new lines with love.filesystem?

Post by FishofMuu »

Okay, I KNEW it was something stupidly easy like that. I'm totally new to LUA this week, so I've never even seen \r before. Thank you.
User avatar
nevon
Commander of the Circuloids
Posts: 938
Joined: Thu Feb 14, 2008 8:25 pm
Location: Stockholm, Sweden
Contact:

Re: Can't start new lines with love.filesystem?

Post by nevon »

FishofMuu wrote:Okay, I KNEW it was something stupidly easy like that. I'm totally new to LUA this week, so I've never even seen \r before. Thank you.
That's actually a Windows idiosyncrasy, IIRC. In OS X or any *NIX system, \n will do exactly what you expect it to. It's only in Windows that you have to do \r\n.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Can't start new lines with love.filesystem?

Post by Robin »

Would it be a good idea to let Files do automatic new-line conversion on Windows?
Help us help you: attach a .love.
User avatar
BlackBulletIV
Inner party member
Posts: 1261
Joined: Wed Dec 29, 2010 8:19 pm
Location: Queensland, Australia
Contact:

Re: Can't start new lines with love.filesystem?

Post by BlackBulletIV »

Wow, this is a pretty bad cross-platform issue. Has an issue been created for this?
User avatar
tentus
Inner party member
Posts: 1060
Joined: Sun Oct 31, 2010 7:56 pm
Location: Appalachia
Contact:

Re: Can't start new lines with love.filesystem?

Post by tentus »

The following code works just fine on my windows XP and windows 7 machines, newlines behave exactly how the *nix user in me expects. (Pruned somewhat for readability.)

Code: Select all

function saveOptions()
	local set = ""
	set = set .. "-- Save File\n"
	set = set .. "-- Created on " .. os.date("%c") .. "\n\n"
	local file = love.filesystem.newFile("settings.lua")
	file:open('w')
	file:write(set)
	file:close()
end
Kurosuke needs beta testers
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Can't start new lines with love.filesystem?

Post by bartbes »

You're both wrong and right. It depends on the editor you open it in. Notepad needs \r\n, but wordpad for example works with just \n as well.
User avatar
BlackBulletIV
Inner party member
Posts: 1261
Joined: Wed Dec 29, 2010 8:19 pm
Location: Queensland, Australia
Contact:

Re: Can't start new lines with love.filesystem?

Post by BlackBulletIV »

bartbes wrote:You're both wrong and right. It depends on the editor you open it in. Notepad needs \r\n, but wordpad for example works with just \n as well.
Oh, I thought he was printing it to the console to test, not viewing in Notepad...
FishofMuu
Prole
Posts: 3
Joined: Fri Mar 18, 2011 9:42 pm

Re: Can't start new lines with love.filesystem?

Post by FishofMuu »

bartbes wrote:You're both wrong and right. It depends on the editor you open it in. Notepad needs \r\n, but wordpad for example works with just \n as well.
Ooooooh, alright. That makes a bit more sense now. Was pulling my hair out over something so simple. I code in Notepad++, but I open random txt files in notepad.
Post Reply

Who is online

Users browsing this forum: Amazon [Bot], Bing [Bot] and 9 guests