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

Please help me with this code!

Started by cibastian, 20 March 2012 - 08:01 AM
cibastian #1
Posted 20 March 2012 - 09:01 AM
i get so frustrated by this whenever i try doing something like that i get some sort of error for this code it's

bios:206: [string "lock"]:10: syntax error
can anyone correct me where ever i am wrong in
Spoiler

pass = "mypasswordhere"
write("password:")
read("*")
if input() == pass then
print("correct")
rs.setOutput("left", true)
sleep(5)
rs.setOutput("left", false)
os.shutdown()

else

print("wrong")
sleep(1)
print("next time get the password right")
rs.setOutput("right", true)
sleep(2)
rs.setOutput("right", false)
os.shutdown()
end
please help me
Luanub #2
Posted 20 March 2012 - 09:11 AM
You called read() without assigning it to the var input



pass = "mypasswordhere"
write("password:")
local input = read("*")	<----- updated
if input == pass then  <---- removed extra ()s
print("correct")
rs.setOutput("left", true)
sleep(5)
rs.setOutput("left", false)
os.shutdown()

else

print("wrong")
sleep(1)
print("next time get the password right")
rs.setOutput("right", true)
sleep(2)
rs.setOutput("right", false)
os.shutdown()
end
cibastian #3
Posted 21 March 2012 - 02:22 AM
ok this works. BTW what does the local before input in the 3rd line suppose to do?
Luanub #4
Posted 21 March 2012 - 03:15 AM
It makes it a local variable. Its good coding practice to use local vars vs global vars. Using global vars can cause some issues and they are a little slower then a local.