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

Is x.readLine(num) broke?

Started by diamondpumpkin, 03 December 2016 - 05:55 AM
diamondpumpkin #1
Posted 03 December 2016 - 06:55 AM
Hello,
I'm not sure if this is just a bug or if the feature was removed. If you were to use my following code

http://pastebin.com/7kcbpydP

you would be able to set the variable j to the second line of the file. However that is no longer the case, as of right now I get 'Hello1' instead of 'Hello2'. I seen on the wiki the description of the function has changed. If this has been removed, how do I use something that worked like the previous?
Anavrins #2
Posted 03 December 2016 - 07:18 AM
readLine never worked like this, you must be confusing it with something else.

Whatever the purpose you have in mind, you can load the whole file easily into a table.

local f = fs.open("test1", "r")
local lines = {}
for line in f.readLine do
  lines[#lines+1] = line
end
And index your line number from the table, in this case, lines[2] will contain "Hello2".
diamondpumpkin #3
Posted 03 December 2016 - 07:32 AM
readLine never worked like this, you must be confusing it with something else.

Whatever the purpose you have in mind, you can load the whole file easily into a table.

local f = fs.open("test1", "r")
local lines = {}
for line in f.readLine do
  lines[#lines+1] = line
end
And index your line number from the table, in this case, lines[2] will contain "Hello2".

I'm very sure it worked like this at one point. I've used it before like I posted and it worked like I posted.
TheRockettek #4
Posted 03 December 2016 - 08:29 AM
theres no argument in readLine to specify what line and it never has. Maybe you were using an api that modifys it :P/>
H4X0RZ #5
Posted 03 December 2016 - 01:03 PM
Not even the first entry of the wiki contains that function signature you used in the snippet above.

http://computercraft.info/wiki/index.php?title=Fs.open&oldid=835
Sewbacca #6
Posted 03 December 2016 - 08:33 PM
readLine reads the line until a \n or till the end and jumps the 'read cursor' behind the \n (if \n is on the fourd letter, the position is 5).
In normal Lua, you would use handle.seek(10) (I am not sure) to set the cursor position to 10.