how do i get a newline in io.write?

Posted by Braindead on Thu 31 May 2007 02:58 PM — 4 posts, 24,977 views.

Netherlands #0
I'm trying to save multiple arrays to the same file, but to read them successfully I need to know how to add a new line to the file.

code used for saving:

Quote:

f = io.output (MobFileName)
c = 0
if ArrayListAll() then
for k, a in pairs (ArrayListAll ()) do
if ArrayKeyExists (a, "Type") then
if ArrayGet (a, "Type") == "Mob" then
c = c + 1
f:write (ArrayExport (a, ";"))
end -- if
end -- if
end -- for
end -- if
f:close ()


code used for loading:

Quote:

f = io.input (MobFileName)
c = 0
repeat
s = f:read ("*l")
if s then
ArrayImport (ArrID,s,";")
some code here to process data
ArrayClear (ArrID)
c = c + 1
end -- if
until not s
f:close ()
Amended on Thu 31 May 2007 03:21 PM by Braindead
USA #1
f:write("\n")

Just tack it on the end of each individual line.
f:write ("foo\n")
Amended on Thu 31 May 2007 03:49 PM by Shaun Biggs
Netherlands #2
Duh, I thought I tried that, but I used /n instead.

Thanks
USA #3
That's ok, if it makes you feel any better, I spent two hours yesterday trying to figure out why I wasn't able to put a \ into a string. Forgot that I needed "\\" to do that.