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

Filesystem reading doesn't seem to work in loops

Started by Chainmanner, 12 June 2014 - 10:55 PM
Chainmanner #1
Posted 13 June 2014 - 12:55 AM
Now, this one's bugging me; in a loop, I'm trying to have a program read lines from a file and insert them into a table. However, the program fails with the error "attempt to index ? (a nil value)". Here's the code:

  if message == "GET_ACCESS_LIST" and protocol == "doorsec" then
   local senderDirectory = fs.combine("PRIME/DOORSEC/SERVER", tostring(sender))
   local senderRead = fs.open(senderDirectory, "r")
   local currentText = "0"
   repeat --Repeatedly get access IDs
    --local senderRead = fs.open(senderDirectory, "r")
    currentText = senderRead.readLine() --Line where the error seems to be
    --senderRead.close()
    if not currentText == nil then
	 table.insert(accessLst, currentText)
    end
   until currentText == nil
   rednet.send(sender, textutils.serialize(accessLst), doorsec)
  end
I haven't tried rebooting the game, but this isn't the only time I've seen this. Are there any solutions to this problem?
Edited on 12 June 2014 - 10:56 PM
Chainmanner #2
Posted 13 June 2014 - 01:20 AM
PROBLEM IDENTIFIED! You can ignore this topic.