This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
11battlek's profile picture

need help in programming a computer

Started by 11battlek, 03 April 2012 - 01:17 PM
11battlek #1
Posted 03 April 2012 - 03:17 PM
need help in my programming what i want it to do is turn on lights (left) and open a door (right) using password lock then needing another password to open another door all on one computer
this is what i have written

print("systerm online")
term.clear()
term.setCursorPos(1,1)
password = "BattleSeure"
debug ="12345"
pass = "12345"
print ("security systerm")
write ("password required: ")
input = read()
term.clear()
term.setCursorPos(1,1)
if input == password then
print ("access granted")
redstone.setOutput ("right", true)
print ("lights online")
sleep(2)
redstone.setOutput ("left", true)
print ("door open")
sleep (5)
redstone.setOutput("left",false)
print ("Safe security")
write "password required: "
input = read()
if input == passthen
print ("safe access granted")
redstone.setOutput ("back",true)
sleep(2)
redstone.setOutput ("right", false)
os.shutdown()
elseif
input == debug then
exit()
else
print("password incorrect!")
sleep(5)
os.shutdown()
end
this is my first time i used other people programs to make this so not all of it was mine it may be miner issues or rookie mistakes thanks for any help
EatenAlive3 #2
Posted 03 April 2012 - 03:40 PM
You should read this: http://www.computercraft.info/forums2/index.php?/topic/475-get-help-faster-read-me/
11battlek #3
Posted 03 April 2012 - 04:00 PM
do u want the error message?
bios:206 [string "startup"]:37: 'end' expected (to close 'if' at line 12)
1v2 #4
Posted 03 April 2012 - 04:18 PM
I've cleaned it up a bit, that error was because you didn't close the if-statement at line 12.


This should work, but I haven't tested it.


local funtion clear()
term.clear()
term.setCursorPos(1,1)
end
local password = "BattleSeure"
local pass = "12345"
local debug = "1234"
os.pullEvent = os.pullEventRaw
print("system online")
clear()
print ("security system")
write ("password required: ")
input = read()
clear()
if input == password then
print ("access granted")
rs.setOutput ("right", true)
print ("lights online")
sleep(2)
rs.setOutput ("left", true)
print ("door open")
sleep (5)
rs.setOutput("left",false)
end
print ("Safe security")
write "password required: "
input = read()
if input == pass then
print ("safe access granted")
rs.setOutput ("back",true)
sleep(2)
rs.setOutput ("right", false)
os.shutdown()
elseif
input == debug then
exit()
else
print("password incorrect!")
sleep(5)
os.shutdown()
end
11battlek #5
Posted 03 April 2012 - 05:18 PM
no doesn't work error bios:206: [string "startup"]:6: unfinished string
11battlek #6
Posted 03 April 2012 - 05:53 PM
I've cleaned it up a bit, that error was because you didn't close the if-statement at line 12.


This should work, but I haven't tested it.


local funtion clear()
term.clear()
term.setCursorPos(1,1)
end
local password = "BattleSeure"
local pass = "12345"
local debug = "1234"
os.pullEvent = os.pullEventRaw
print("system online")
clear()
print ("security system")
write ("password required: ")
input = read()
clear()
if input == password then
print ("access granted")
rs.setOutput ("right", true)
print ("lights online")
sleep(2)
rs.setOutput ("left", true)
print ("door open")
sleep (5)
rs.setOutput("left",false)
end
print ("Safe security")
write "password required: "
input = read()
if input == pass then
print ("safe access granted")
rs.setOutput ("back",true)
sleep(2)
rs.setOutput ("right", false)
os.shutdown()
elseif
input == debug then
exit()
else
print("password incorrect!")
sleep(5)
os.shutdown()
end
no doesn't work error bios:206: [string "startup"]:6: unfinished string
Cloudy #7
Posted 03 April 2012 - 08:18 PM
I'll point out the line causing the issue. See if you can spot what is wrong.

local funtion clear()
virtualayu #8
Posted 08 April 2012 - 03:58 AM
function not funtion
and maybe i'm wrong but i think you can't create a function named clear() , i'm not sure…
anyway it'll be better to name it clearScreen() or something like that but it's just for an easy reading of your code…

and i really don't understand why you use local term to declare a function or a variable…. your program is so small… you don't need it… and declaring local vars is only if you declare it inside a function… (maybe i'm wrong?) declaring a variable like you did is useless because it will be declare as a global one anyway… (aigain i'm maybe wrong… XD)