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

writing text on a new line

Started by RadimBur, 03 November 2015 - 07:26 PM
RadimBur #1
Posted 03 November 2015 - 08:26 PM
EN: Hi, I would like to ask if anyone knew how to make a program. A program that opens a file and writes instructions and closes the file. And when it will be open after the second, the third, …. to ever write instruction on the next line. Thank you for responses


CZ: Ahoj, chtěl bych se zeptat, jestli by někdo věděl, jak udělat program. Program, který si otevře soubor a zapíše do něj instrukce a zavře soubor. A když ho bude otevírat po druhé, po třetí,…. aby vždy zapsal instrukce na další řádek. Děkuji za odpovědi
KingofGamesYami #2
Posted 03 November 2015 - 08:33 PM

local file = fs.open( "filename", "a" ) --#opens a file in append mode
file.write( "This is a line!" ) --#writes a line to the file (note: since in append mode, the rest of the file will be unchanged)
file.close() --#closes the file
RadimBur #3
Posted 03 November 2015 - 10:12 PM
Thanks you,

but This code writes this: This is a line!This is a line!This is a line!This is a line!

I'd like to write like this:

This is a line!
This is a line!
This is a line!
This is a line!
Edited on 03 November 2015 - 09:12 PM
KingofGamesYami #4
Posted 03 November 2015 - 10:17 PM
Change write to writeLine, like so:


local file = fs.open( "filename", "a" ) --#opens a file in append mode
file.writeLine( "This is a line!" ) --#writes a line to the file (note: since in append mode, the rest of the file will be unchanged)
file.close() --#closes the file
RadimBur #5
Posted 03 November 2015 - 10:25 PM
Its works. Thanks you :)/>