Jump to content


eastar

Member Since 21 May 2015
Offline Last Active Aug 04 2019 11:51 AM
-----

Posts I've Made

In Topic: Reading and writing files

01 July 2019 - 07:31 PM

 Dog, on 30 June 2019 - 04:32 PM, said:

Using h.readLine() you could do this...
local myTable = { }
local myFile = fs.open("/myFile", "r")
repeat --# start a loop that ends with a condition
  local line = myFile.readLine()
  if line then --# if the line read is not nil then add it to the table
	myTable[#myTable + 1] = line
  end
until line == nil --# end the loop if the line read is nil
myFile.close()

OMG!!!
Thank you so much! :)

In the meantime I realised Lupus950 made a typo and meant textutils.serialize() and not textureils.serialize(). So I went with that one. But I'm glad you showed me this method. It makes sense now why there are loops that test the conditions at the end of the loop!

Big thanks to both of ya! :)

In Topic: Reading and writing files

30 June 2019 - 01:47 PM

 Dog, on 29 June 2019 - 08:38 PM, said:

For the format you're using, I'd suggest using io.lines to read the file...
--# read the data
local myTable = { } --# declare and localize your table that will hold the data
for data in io.lines("/myFile") do --# start a loop that stops at the last data line in the file
  myTable[#myTable + 1] = data --# add the next line of data to the next table entry
end

--# print the data
for i = 1, #myTable do
  print(myTable[i])
end

Thank you for the help! :)
Sadly in my version of CC io.lines() doesn't exist. (I'm using CC 1.5)
But thank you! I'l try something similar with h.readLine()!

In Topic: Reading and writing files

29 June 2019 - 04:47 PM

What I specifically would like is:
If I have a file containing data like this:
on
40
off
0
on
32
off
0
on
1

How would you read that into a table? especially if the you don't know how many lines the file contains.

Thanks again! :)

In Topic: Reading and writing files

29 June 2019 - 02:51 PM

 Lupus590, on 29 June 2019 - 01:10 PM, said:

Have you read the wiki? Specifically the return value of fs.open

Sorry, I probably don't understand you, but I have no idea how that could help me.
I do know how to open a file. I also know how to read or write a line to/from a file.

What I don't know is how to read multiple lines without much hassle.

But thanks for the help!