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

string to variable?

Started by gergo654, 04 August 2016 - 01:36 PM
gergo654 #1
Posted 04 August 2016 - 03:36 PM
i dont know how to describe this but i have an example file that has this in it:
hello
hi
bye
and I want to read it as separate variables like so
1 = "hello"
2 = "hi"
3 = "bye"
for example
because a,b,c = file.readAll() does not work like that :I
is that possible?
Thank you <3 :)/>
valithor #2
Posted 04 August 2016 - 04:23 PM

h=fs.open(file,"r")
a=h.readLine()
b=h.readLine()
c=h.readLine()
h.close()
Edited on 04 August 2016 - 02:24 PM
gergo654 #3
Posted 04 August 2016 - 04:30 PM
Thank you
Bomb Bloke #4
Posted 05 August 2016 - 02:39 AM
Or, using a table and io.lines():

local lines = {}

for line in io.lines(file) do
  lines[#lines + 1] = line
end