Posted 12 March 2015 - 12:50 AM
Hello guys,
I have a program that is designed as a PM service ingame as part of an OS I am developing. Part of the program receives data collected from another program (the OS) via a file with the data stored in it. I have checked, and the file is generated and populated properly. I just can't seem to read it. When I try to run the program I get the error
Here is the code:
Gatt427
I have a program that is designed as a PM service ingame as part of an OS I am developing. Part of the program receives data collected from another program (the OS) via a file with the data stored in it. I have checked, and the file is generated and populated properly. I just can't seem to read it. When I try to run the program I get the error
mail:61: attempt to index ? (a nil value)
The error is caused in the line:
line = file.readLine()
I know that normally this is caused by misspelling a function or method, but all my spelling seems to be in order. Here is the code:
--Variables
local vQuit = false
local numOfMessages = 0
local messages = {"m1", "m2", "m3"}
local functionList = {"list", "help", "clear", "quit"}
local functionListReal = {list, help, clear, quit}
local mainPath = "/GoldOS"
local mailPath = mainPath.."/data/mail"
--Startup function (Tell user they have messages)
function startup()
term.clear()
rednet.open("back")
print("Welcome to Mail, you have "..numOfMessages.." new messages.")
print(" ")
print("Type 'list' to see a list of messages or 'help' for more commands")
readIt()
return
end
--Read user response
function readIt()
recieve()
local input = read()
for i,v in ipairs(functionList) do
if input==v then
functionListReal[i]()
end
end
return
end
--List messages
function list()
for i,v in ipairs(messages) do
print(v)
end
readIt()
return
end
--clear screen
function clear()
term.clear()
readIt()
return
end
--Give command help
function help()
--output some help commands
print("type 'list' to list messages")
print("type 'quit' to exit Mail")
print("type 'clear' to clear previous actions from screen")
readIt()
return
end
--Add message to list
function recieve()
local file = fs.open(mailPath, "r")
while not line == nil do
line = file.readLine()
table.insert(messages, line)
numOfMessages = numOfMessages+1
end
file.close()
end
--quit the mail application
function quit()
vQuit = true;
os.reboot()
return
end
startup()
Thanks in advance,Gatt427