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

How can I use the data from fs.open?

Started by Matrixmage, 04 November 2012 - 06:39 AM
Matrixmage #1
Posted 04 November 2012 - 07:39 AM
Hi, I've never really used the fs API and I am trying to make a disk verification system for my friend, and I need to store the data on a file on the disk, how would I use the data I get from fs.open? (sorry for the redundancy, I'm doing this quickly)

P.S. I'm using tekkit so I have 1.3 of CC

also if I want to use the http API do I have to have it on on the server or just the client, or both?

Thanks in advance!
kazagistar #2
Posted 04 November 2012 - 07:45 AM
I don't understand exactly what you are trying to do. What kind of data are you working with? How do you want it to be stored into files? What is the "server" and "client" you are talking about in this context, and what does each one do?

(Also, your sig is missing and "end" at the end, and it is setting off my OCD all over the place :D/>/> )
Matrixmage #3
Posted 04 November 2012 - 08:08 AM
By server and client I am talking about my minecraft client and the tekkit server that I use. And the data I would use would be a name and some kind of code for the person that the disk is for. The kind of data would a simple file (disk/ID perhaps?).
nolongerexistant #4
Posted 04 November 2012 - 09:28 AM
Do you mean something like


local file = fs.open("filename", "w") -- You can use "a" to append to the file
local stuffToWrite = "stuff"

file.write(stuffToWrite)

And it will write "stuff" to the file, then you can read it using


local file = fs.open("filename", "r")
local linesTable = { ... }
i = 1

while true do
  local lineRead = file.readLine()

  if not lineRead then break end -- Break if it reached the end of the file
  table.insert(linesTable, i, lineRead) -- Insert the line into a table
  i = i+1
end


Then you can use it like

print(linesTable[4])
and it will print the 4th line of the file
kazagistar #5
Posted 04 November 2012 - 09:38 AM
If you are playing on a SMP server, then all the the programs and stuff on the disk will be stored on the server.
remiX #6
Posted 05 November 2012 - 01:36 AM
Do you mean something like


local file = fs.open("filename", "w") -- You can use "a" to append to the file
local stuffToWrite = "stuff"

file.write(stuffToWrite)

And it will write "stuff" to the file, then you can read it using


local file = fs.open("filename", "r")
local linesTable = { ... }
i = 1

while true do
  local lineRead = file.readLine()

  if not lineRead then break end -- Break if it reached the end of the file
  table.insert(linesTable, i, lineRead) -- Insert the line into a table
  i = i+1
end


Then you can use it like

print(linesTable[4])
and it will print the 4th line of the file

You didn't do file.close() once :D/>/>