Page 1 of 1

How do I append to a new line using love.filesystem.append?

Posted: Fri Jun 19, 2020 11:56 am
by Bogdan705
I am making a random color generator where no two colors are the same. I am having problems with appending to a new line. I've tried using this advice : https://www.reddit.com/r/love2d/comment ... _log_file/, but adding "\n" at the beginning or end of the string does nothing. So my question is, how do I append to a new line?
By the way, here is the code that does the appending :

Code: Select all

local string = tostring(generated_color[1]) .. "," .. tostring(generated_color[2]) .. "," .. tostring(generated_color[3]) .. "\n"
love.filesystem.append("colors.txt",string)

Re: How do I append to a new line using love.filesystem.append?

Posted: Fri Jun 19, 2020 1:47 pm
by zorg
the \n is still there, saved into the file; the thing is, line breaks differ per OS; windows uses both carriage return and line feed in that order, so you would need to insert \r\n instead of just \n... (linuxes/unices use just \n, and old macos used just \r, idk if OS X uses \n or not though)

that said, in most cases, people indeed just use \n and use a text/code editor that has an option (or auto-detection) regarding what character is used for newlines.