Jump to content




key card programm stops


  • You cannot reply to this topic
7 replies to this topic

#1 darcline

  • Members
  • 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

#2 Kingdaro

    The Doctor

  • Members
  • 1,636 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.

#3 darcline

  • Members
  • 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 ?

#4 cmurtheepic

  • Members
  • 158 posts
  • Locationthe vast cosmos of my mind; binary!

Posted 25 November 2012 - 06:26 AM

you have to name the floppy disk

#5 cmurtheepic

  • Members
  • 158 posts
  • Locationthe 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/>

#6 cmurtheepic

  • Members
  • 158 posts
  • Locationthe 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

#7 Kingdaro

    The Doctor

  • Members
  • 1,636 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.

#8 darcline

  • Members
  • 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





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users