Posted 18 June 2016 - 04:54 PM
Hi I just had a quick question regarding filesystems in computercraft.
I'm trying to create a password program that uses a keycard.
I came across this guide:
http://www.computerc...ng-from-a-file/
which uses the "assert" function to validate the directory that the computer attempts to access, and if assert fails it will instead return an error. My problem is that I can't seem to act on this information.
if i do this:
Then the program will exit at this line and give an error like "failed to assert!" or something, but since this is a password protected door I can't have the program exit :P/> so I tried using an if statement like this:
which doesn't seem to work (gives [expected ")" at line 54] error). So now I'm looking for ideas as to how I can make sure the directory is accesible without throwing an error that stops the program from running. Ideally I'd want something like my if statement so I can do something else in case of an error.
All suggestions are appreciated!
I'm trying to create a password program that uses a keycard.
I came across this guide:
http://www.computerc...ng-from-a-file/
which uses the "assert" function to validate the directory that the computer attempts to access, and if assert fails it will instead return an error. My problem is that I can't seem to act on this information.
if i do this:
local hRead = assert(fs.open(sFile, "r"))
Then the program will exit at this line and give an error like "failed to assert!" or something, but since this is a password protected door I can't have the program exit :P/> so I tried using an if statement like this:
if hRead = assert(fs.open(sFile, "r")) then
sPass = hRead.readLine()
hRead.close()
else
disk.eject(tostring(driveSide))
sleep(2)
end
which doesn't seem to work (gives [expected ")" at line 54] error). So now I'm looking for ideas as to how I can make sure the directory is accesible without throwing an error that stops the program from running. Ideally I'd want something like my if statement so I can do something else in case of an error.
All suggestions are appreciated!