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

io.open Specific Lines

Started by coolblockj, 02 March 2012 - 10:00 PM
coolblockj #1
Posted 02 March 2012 - 11:00 PM
I was just wondering, is there a way to choose specific lines for it to read?
Liraal #2
Posted 02 March 2012 - 11:03 PM
I'd say: read all and then select a line. Probably simplest way, unless - which i doubt - there is actually a way to do that with io.read().
Casper7526 #3
Posted 02 March 2012 - 11:38 PM
There is no file:seek() ect in CC, you can however use file:lines() if you want to read through all the lines of a file much quicker :unsure:/>/>


for line in file:lines() do print(line) end
coolblockj #4
Posted 06 March 2012 - 04:19 AM
I'd say: read all and then select a line. Probably simplest way, unless - which i doubt - there is actually a way to do that with io.read().
How would i select i line?

There is no file:seek() ect in CC, you can however use file:lines() if you want to read through all the lines of a file much quicker :unsure:/>/>


for line in file:lines() do print(line) end
I don't see how i could use this to read a specific line…
Advert #5
Posted 06 March 2012 - 04:24 AM
You could do this:


local tFile = {}

local hHandle = fs.open("file", "r")
repeat
local line = hHandle:readLine()
table.insert(tFile, line)
until not line
hHandle:close()
print(tFile[3]) -- Gets line 3
print(tFile[10]) -- Gets line 10