This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
wilcomega's profile picture

help with my file writing problem

Started by wilcomega, 29 July 2012 - 02:03 AM
wilcomega #1
Posted 29 July 2012 - 04:03 AM
i have made a program that writes a table to a file line by line but on every line it writes 'table: (numbers)'
here is the PIECE code:


local f = fs.open( "keys.txt", "w" )
local toWrite = ""
for i=1,#logging do
toWrite = logging[i]
f:writeLine( toWrite )
if debug == true then print( "writed: ", logging[i] ) end
end
f:close( )

thx in adv :ph34r:/>/>

edit: if you want full code just ask. i am not going to give it in public, i will PM you :)/>/>
Luanub #2
Posted 29 July 2012 - 07:48 AM
I'm not sure why you are doing this

toWrite = logging[i]
f:writeLine( toWrite )

It's probably what is causing your error, try just this.

f:writeLine(logging[i])
Lyqyd #3
Posted 29 July 2012 - 08:43 AM
Yeah, there's nothing visibly wrong with that code. Luanub mentioned a bad coding practice to correct, but even that shouldn't be causing the problem. Let's see the rest of it.
ChiknNuggets #4
Posted 29 July 2012 - 11:36 AM

local f = fs.open("keys.txt", "w")
for i,v in ipairs(logging) do
if i == 1 then text = v else text = text.."n"..v end
if debug == true then print( "writed: ", v ) end
end
f.write(text)
f:close()

Will do what you want, i tested it and it worked