33 posts
Posted 25 November 2012 - 04:33 AM
hello i have build me an keycard programm but when i took a keycard in and the keycard is empty the programm goes down i hope you can help me its the line 7 when i put a empty card in the Disk Drive
term.clear()
term.setCursorPos(1, 1)
print("Sicherheitskarte einlegen")
while true do
event = os.pullEvent("disk")
sFile = "disk/secureaccess"
hRead = assert(fs.open(sFile, "r"))
sPass = hRead.readLine()
hRead.close
if sPass == "secureaccesscode" then
print("Zugriff gewährt")
redstone.setOutput("bottom", true)
sleep(10)
os.reboot()
else
print("Zugriff Verweigert")
sleep(3)
os.reboot()
end
end
1688 posts
Location
'MURICA
Posted 25 November 2012 - 04:44 AM
I think it would be safer to simply check if the file handle exists, rather than to error if it doesn't.
33 posts
Posted 25 November 2012 - 05:23 AM
ahm i found this is for an new user in lua for first enough.
ahm how i build the error code in the assert ?
145 posts
Location
the vast cosmos of my mind; binary!
Posted 25 November 2012 - 06:26 AM
you have to name the floppy disk
145 posts
Location
the vast cosmos of my mind; binary!
Posted 25 November 2012 - 06:40 AM
and i dont really know how to make it where it is constantly listening for a rednet message?
but i am going to add on to it the part where is sees if the rednet message is equal to any of the user-defined ores. be back with the coding soon :D/>/>
oh and ill try not to make it messy :P/>/>
145 posts
Location
the vast cosmos of my mind; binary!
Posted 25 November 2012 - 06:42 AM
i mean constantly listening for a rednet message in the background and then comparing it to the table of ore varable
1688 posts
Location
'MURICA
Posted 25 November 2012 - 07:11 AM
Here's a fixed script:
term.clear()
term.setCursorPos(1, 1)
print("Sicherheitskarte einlegen")
while true do
event = os.pullEvent("disk")
sFile = "disk/secureaccess"
hRead = fs.open(sFile, "r") -- removed assert() so the script does not stop
if hRead then -- check if hRead exists
sPass = hRead.readLine()
hRead.close() -- added brackets
if sPass == "secureaccesscode" then
print("Zugriff gewährt")
redstone.setOutput("bottom", true)
sleep(10)
redstone.setOutput("bottom", false)
-- no need for rebooting
else
print("Zugriff Verweigert")
sleep(3)
end
else
print("Ungültige Karte")
end
end
Comments where I made changes.
33 posts
Posted 25 November 2012 - 07:42 AM
some realy thanks for you :D/>/> i have doing some to what you do but with the if i had a bad argument createt :P/>/> thanks script works