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

Reading Line by Line

Started by Hobby_Crafter, 10 October 2014 - 06:00 PM
Hobby_Crafter #1
Posted 10 October 2014 - 08:00 PM
Hi,
I would like to make a program which reads a file and shows his content on a monitor.
But my problem is, when i read the file with:

mon = peripheral.wrap("right")
mon.setCursorPos(1,1)

file = fs.open("file","r")
x = file.readLine()
file.close()

mon.write(x)

the whole text of the file is written in the first line on the monitor.

Thanks for your support. PS: Sorry for my english … I'm a german :D/>
KingofGamesYami #2
Posted 10 October 2014 - 08:37 PM
Two options here:
1 - Use print. It will automatically format lines that are too long, and recognise the new line symbols.
2 - Make your own render thing. Here's a very basic one:

local y = 1
for line in x:gmatch( "[^\r\n]*" do
  term.setCursorPos( 1, y )
  term.write( line )
  y = y + 1
end
Hobby_Crafter #3
Posted 10 October 2014 - 08:55 PM
Thanks for the fast reply :D/>