Posted 14 May 2012 - 03:37 PM
I've made my first ever program on Computercraft and in any programing language. Its allows you to open a door for a spsific and lets you set a user name and pasword to lock the commputer. apart from the bad splling the program works how i want it to but I know it can be smplafied and improved. So i guess my question is how?
term.clear()
term.setCursorPos(1,1)
x = 10
function resetpassword()
while true do
term.clear()
term.setCursorPos(1,1)
write ('Set User Name: ')
rename = io.read()
write ('set Password : ')
repassword = io.read()
print (' ')
print ('Youre User Name is '..rename)
print ('Youre password is '..repassword)
print (' ')
write ('Do you conferm this? ')
passwordconferm = io.read()
if passwordconferm == 'yes' then
print (' ')
print ('Infomation confermed')
rename = username
repassword = userpassword
sleep (2.5)
term.clear()
term.setCursorPos(1,1)
break
else
print (' ')
print ('Infomation is incorrect')
print (' ')
write ('Do you wish to repeat reset? ')
repeatpasswordset = io.read()
if repeatpasswordset == 'yes' then
print (' ')
else
break
end
end
end
end
function opendoor()
term.clear()
term.setCursorPos(1,1)
sleep(0.5)
redstone.setOutput('left', true)
while x >-1 do
print (x)
sleep(1)
x = x - 1
end
redstone.setOutput('left', false)
sleep(1)
term.clear()
term.setCursorPos(1,1)
sleep(1)
end
function interface()
while true do
term.clear()
term.setCursorPos(1,1)
print "----------------------------------------------"
print "| Door conrtrol panel |"
print "| By: Jacob7395 |"
print "----------------------------------------------"
print "| |"
print "| 1. open door |"
print "| 2. Lock panel |"
print "| 3. Settings |"
print "| 4. exit |"
print "| |"
print "| |"
print "----------------------------------------------"
event, param1, param2, param3 = os.pullEvent()
if event == "char" and param1 == "1" then opendoor() end
if event == "char" and param1 == "2" then password() end
if event == "char" and param1 == "3" then interfacesettings() end
if event == "char" and param1 == "4" then break end
end
end
function setpassword()
while true do
term.clear()
term.setCursorPos(1,1)
write ('Set User Name: ')
setname = io.read()
write ('set Password : ')
setpassword = io.read()
print (' ')
print ('Youre User Name is '..setname)
print ('Youre password is '..setpassword)
print (' ')
write ('Do you conferm this? ')
passwordconferm = io.read()
if passwordconferm == 'yes' then
print (' ')
print ('Infomation confermed')
username = setname
userpassword = setpassword
sleep (2.5)
term.clear()
term.setCursorPos(1,1)
break
else
print (' ')
print ('Infomation is incorrect')
print (' ')
print ('User name and password must be seet ')
sleep(2)
end
end
end
function interfacesettings()
while true do
term.clear()
term.setCursorPos(1,1)
print "----------------------------------------------"
print "| Door conrtrol panel settings |"
print "| By: Jacob7395 |"
print "----------------------------------------------"
print "| |"
print "| 1. open door timer |"
print "| 2. reset username and password |"
print "| 3. exit |"
print "| |"
print "| |"
print "| |"
print "----------------------------------------------"
event, param1, param2, param3 = os.pullEvent()
if event == "char" and param1 == "1" then
setdoortimer()
end
if event == "char" and param1 == "2" then
resetpassword()
end
if event == "char" and param1 == "3" then break end
end
end
function setdoortimer()
term.clear()
term.setCursorPos(1,1)
print "----------------------------------------------"
print "| Door timer settings |"
print "| By: Jacob7395 |"
print "----------------------------------------------"
print "| |"
print "| Set door timer to (s): |"
print "| |"
print "| |"
print "| |"
print "| |"
print "| |"
print "----------------------------------------------"
term.setCursorPos(26,6)
write ('')
x = io.read()
x = tonumber(x)
end
function password()
while true do
term.clear()
term.setCursorPos(1,1)
write ('User Name: ')
name = io.read()
if name == username then
write ('Password: ')
password = io.read()
if password == userpassword then
write ('access granted')
sleep(1)
write ('.')
sleep(1)
write ('.')
sleep(1)
print ('.')
sleep(1)
break
else
write ('incorrect information')
sleep(1)
write ('.')
sleep(1)
write ('.')
sleep(1)
print ('.')
sleep(1)
end
else
write ('incorrect information')
sleep(1)
write ('.')
sleep(1)
write ('.')
sleep(1)
print ('.')
sleep(1)
end
end
term.clear()
term.setCursorPos(1,1)
end
term.clear()
term.setCursorPos(1,1)
print ('Welcome to the door control program')
print (' ')
sleep(2)
print ('This program will allow you to securly control the door')
print (' ')
sleep(2)
write ('Fisrt you must set the User name and password')
sleep(2)
write ('.')
sleep(2)
write ('.')
sleep(2)
write ('.')
sleep(2)
write ('.')
sleep(2)
write ('.')
term.clear()
term.setCursorPos(1,1)
setpassword()
print ('User name and Password set')
print (' ')
write ('Processing to door controle pannle pleace wait')
sleep(2)
write ('.')
sleep(2)
write ('.')
sleep(2)
write ('.')
sleep(2)
term.clear()
term.setCursorPos(1,1)
interface()
term.clear()
term.setCursorPos(1,1)