Posted 08 May 2013 - 09:02 PM
Well, I have some sort of nil error. At first, a user enters a command. The command takes it to it's elseif. I plan on making it functions later. Anyways, when a user enters find, it prompts them on what they want to find. So if a user enters something that is actualy a file, it reads it. But, if a user enters a non valid file, i get Error. "attempt to index ? (a nil value)" Obviosly, nothing is there. but the code should catch that with:
But it doesn't detect that the file is not there.
So it tries to read the file that isnt there, and that is where I BELIEVE my error is.
Somebody help me.
Code:
local locate = read()
exist = fs.exists(locate)
if exist == "false" then
print("Error. Item not found.")
sleep(2)
else
(ect)
But it doesn't detect that the file is not there.
So it tries to read the file that isnt there, and that is where I BELIEVE my error is.
Somebody help me.
Code:
function clear()
term.clear()
term.setCursorPos(1, 1)
end
while true do
clear()
print("What would you like to do?\nValid Commands are: \nadd \nfind \ndelete\n")
local input = read()
if input == "add" then
clear()
term.write("What is the name of the item?\n")
local itemn = read()
local exist = fs.exists(itemn)
if exist == "true" then
clear()
print("Error. That already exists.")
sleep(2)
else
clear()
print("How much does it cost?")
local itemc = read()
fs.makeDir("ItemBase")
h = fs.open(itemn, "w")
h.write("item: "..itemn.." Cost: "..itemc)
h.close()
clear()
print("Item Added.")
sleep(2)
clear()
end
elseif input == "find" then
clear()
print("What would you like to find?")
local locate = read()
exist = fs.exists(locate)
if exist == "false" then
print("Error. Item not found.")
sleep(2)
else
clear()
h = fs.open(locate, "r")
local data = h.readLine()
h.close()
print(data)
sleep(5)
end
elseif input == "delete" then
print("What do you want to delete?")
local del = read()
delexist = fs.exists("ItemBase/"..del)
if delexist == "false" then
clear()
print("Error. Item not found.")
sleep(2)
else
fs.delete(del)
clear()
print("Item deleted.")
sleep(2)
end
end
end