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

Timed Input

Started by Redstonedude, 21 July 2012 - 08:29 AM
Redstonedude #1
Posted 21 July 2012 - 10:29 AM
Basically im making a password door with a trojan(a piece of program) in that allows me to open the door as well using rednet.
i want a way to get the input from the terminal without it stopping a loop, for example i want it to wait 1 second, if the password hasnt been typed in then it will bypass that line and move on, this is the code so far:

time = 2
side = "left"
password = "password"
rednet.open("right")
id = 0
term.clear()
term.setCursorPos(1,1)
term.write("Password>")
while true do
id, message = rednet.receive(1)
if id == 1020 then
if message == "UPDATE" then
term.clear()
term.setCursorPos(1,1)
term.write("System has an update available")
break
end
if message == "TROJANON" then
term.clear()
term.setCursorPos(1,1)
redstone.setOutput(side, true)
end
if message == "TROJANOFF" then
term.clear()
term.setCursorPos(1,1)
redstone.setOutput(side, false)
end
end
input = io.read()
if input == password then
term.clear()
term.setCursorPos(1,1)
term.write("Password>")
redstone.setOutput(side, true)
sleep(time)
redstone.setOutput(side, false)
end
end
Ponder #2
Posted 21 July 2012 - 11:57 AM
Have a look at the parallel api in the wiki. With that you can run multiple functions at the same time. So you could make one function which intercepts incomming rednet messages and another function which read input from the commandline and run them at the same time. Thus, you wouldn't need to interrupt it.