I am trying to create a program that reads every file in a directory and prints out everything. This is my Code so far: http://pastebin.com//wPHnN0dQ
I get the error attempt to index ? (a nil value) in line 179 I just don't know why my line is defined so I don't know.
1
4 replies to this topic
#1
Posted 21 April 2015 - 03:25 PM
#2
Posted 21 April 2015 - 03:30 PM
If you look at line 179 you have:
Attempt to index nil means in this case that the file variable is nil. This is a result of opening a file that doesn't exist. Line 178 has
Turtles should be Turtles/ instead - you are opening a file called TurtlesWhatever instead of Turtles/Whatever.
Also instead of using a for i = 0, ... loop you can do:
line = file.readLine() -- This function reads the next line in the file, until the end.
Attempt to index nil means in this case that the file variable is nil. This is a result of opening a file that doesn't exist. Line 178 has
file = fs.open("Turtles"..turtleDataFiles[i],"r") -- Open a file for reading.
Turtles should be Turtles/ instead - you are opening a file called TurtlesWhatever instead of Turtles/Whatever.
Also instead of using a for i = 0, ... loop you can do:
for _, name in pairs(fs.list("Turtles/")) do
Edited by SquidDev, 21 April 2015 - 03:31 PM.
#3
Posted 21 April 2015 - 03:33 PM
Also remember that fs.list returns directories too. So you will need to add a check before you open the file to make sure it is not a directory.
#4
Posted 22 April 2015 - 12:13 PM
Ok thanks that worked but apparently I have a bug in my printing function called bigTable it starts at line 99. It should print out everything in every file each file should represent one line that doesn't work it just prints out everything in one line. This is my code: http://pastebin.com/R5hY1ihk
#5
Posted 22 April 2015 - 03:40 PM
Ok sorry I found the mistake I forgot to reset the table and I had some other mistakes in there thanks for your help.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users