Jump to content




How can I use the data from fs.open?


  • You cannot reply to this topic
5 replies to this topic

#1 Matrixmage

  • Members
  • 116 posts
  • LocationAt my Computer coding for the Computer in my Computer

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!

#2 kazagistar

  • Members
  • 365 posts

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/> )

#3 Matrixmage

  • Members
  • 116 posts
  • LocationAt my Computer coding for the Computer in my Computer

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?).

#4 nolongerexistant

  • Validating
  • 201 posts
  • LocationNetherlands

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

#5 kazagistar

  • Members
  • 365 posts

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.

#6 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

Posted 05 November 2012 - 01:36 AM

View PostSnakybo, on 04 November 2012 - 09:28 AM, said:

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/>





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users