Posted 09 April 2013 - 09:20 PM
Hi guys! First, i'm very new on ComputerCraft, and i have 0 skill in programming language, and this is my FIRST code!
I have a little trouble with my code, for now the code run very well, but i want to add a "feature", and can't figure out the problem… i have spent 4 hours trying figure out by myself, and the problem is not solved….
[Scenario]
I have my room, and the computer ask password to people to open the door, if the user insert wrong password for three times under her feet, a trapdoor opens, and the user fall down…
[Problem]
The code work fine, but i want add a button on back of my computer, to open the door when i'm in my room, and i do not want to type password again.
[Suspects]
Reading over the web, and figure out by myself, I've understand it is the [read] command, which blocks my code.
This is my code:
[Notes:]
The door is formed by sticky pistons and the closed state is "true", the color of cable is white
The trap is formed by sticky pistons and the deactivated state is "true", the color of cable is lightBlue
Well, that is all… Anyone can help me? Sorry for my very bad english i'm italian, but I hope I explained the problem well…
Thanks in advance for the help!
I have a little trouble with my code, for now the code run very well, but i want to add a "feature", and can't figure out the problem… i have spent 4 hours trying figure out by myself, and the problem is not solved….
[Scenario]
I have my room, and the computer ask password to people to open the door, if the user insert wrong password for three times under her feet, a trapdoor opens, and the user fall down…
[Problem]
The code work fine, but i want add a button on back of my computer, to open the door when i'm in my room, and i do not want to type password again.
[Suspects]
Reading over the web, and figure out by myself, I've understand it is the [read] command, which blocks my code.
This is my code:
os.pullEvent = os.pullEventRaw
local password = "bacon"
local tempoPorta = 5
local tempoTrappola = 3
local tentativo = 0
function clear()
term.clear()
term.setCursorPos (1,1)
end
function bypass()
rs.setBundledOutput("left", colors.lightBlue)
sleep(tempoPorta)
rs.setBundledOutput("left", colors.lightBlue+colors.white)
accesso()
end
function login()
if tentativo == 3 then
maxTentativi()
else
clear()
write("Inserire Password:")
local input = read ("*")
if input == password then
clear()
print("Passowrd Corretta!")
rs.setBundledOutput("left", colors.lightBlue)
sleep(tempoPorta)
rs.setBundledOutput("left", colors.lightBlue+colors.white)
else
clear()
tentativo = tentativo + 1
print("Password Sbagliata!")
print("Tentativo: ",tentativo)
sleep(2)
end
end
end
function maxTentativi()
rs.setBundledOutput("left", colors.white)
sleep(tempoTrappola)
tentativo = 0
accesso()
end
function accesso()
rs.setBundledOutput("left", colors.lightBlue+colors.white)
while true do
login()
end
end
accesso()
[Notes:]
The door is formed by sticky pistons and the closed state is "true", the color of cable is white
The trap is formed by sticky pistons and the deactivated state is "true", the color of cable is lightBlue
Well, that is all… Anyone can help me? Sorry for my very bad english i'm italian, but I hope I explained the problem well…
Thanks in advance for the help!