Posted 11 June 2012 - 12:12 PM
For example, I wrote a password door. It works well. However, when I save&quit the game and come back later. The virtual computer which controls the door restarts and it's not running the program. What should I do?
The code follows:
–To prevent others from openning the door by using a redstone signal, I set the door perpendicular to the frame, instead of parallel. So it's "closed"(opened actually)when it receives a redstone signal. It will "open"(actually close) when the signal disappear.
os.pullEvent = os.pullEventRaw
password="0000"
rs.setOutput("right",true)– Keep the door "closed"
while true do
term.clear()
print "Input password"
input=read("*")
if input==password then
term.clear()
print "ID confirmed\n"
print "Input \"reset\" to reset the password\n"
print "Or input any other word to open the door\n"
cmd=io.read();
if(cmd=="reset") then
done=false
while not done do
print "Input the new password\n"
newpass=read("*")
print "Please input again to confirm\n"
confirm=read("*")
if(newpass==confirm) then
password=newpass
done=true
term.clear()
print "Password reset!\n"
else
print "The two passwords are different, please input again\n"
end
end
else
rs.setOutput("right",false)
sleep(4)
rs.setOutput("right",true)
end
else
print "Wrong password\n"
print "Access Denied\n";
end
end
The code follows:
–To prevent others from openning the door by using a redstone signal, I set the door perpendicular to the frame, instead of parallel. So it's "closed"(opened actually)when it receives a redstone signal. It will "open"(actually close) when the signal disappear.
os.pullEvent = os.pullEventRaw
password="0000"
rs.setOutput("right",true)– Keep the door "closed"
while true do
term.clear()
print "Input password"
input=read("*")
if input==password then
term.clear()
print "ID confirmed\n"
print "Input \"reset\" to reset the password\n"
print "Or input any other word to open the door\n"
cmd=io.read();
if(cmd=="reset") then
done=false
while not done do
print "Input the new password\n"
newpass=read("*")
print "Please input again to confirm\n"
confirm=read("*")
if(newpass==confirm) then
password=newpass
done=true
term.clear()
print "Password reset!\n"
else
print "The two passwords are different, please input again\n"
end
end
else
rs.setOutput("right",false)
sleep(4)
rs.setOutput("right",true)
end
else
print "Wrong password\n"
print "Access Denied\n";
end
end