Posted 09 June 2012 - 07:50 PM
I need help with my door-lock-programm. Entering password to get inside and just press a button to get outside. I already tried those parts an their own and they work, however now I'm stuck with combining them.
I do have quite a bit of programming experience (although not in lua) but I never had to use multitasking.
[indent=1]term.clear()
term.setCursorPos(1,1)
print("Please enter password:")
t=read("*")[/indent]
[indent=1]
if t == "chamber" then[/indent]
[indent=2]rs.setBundledOutput("bottom", 0)
os.sleep(5)
rs.setBundledOutput("bottom", 2048)[/indent]
[indent=1]else[/indent]
[indent=2]print("Wrong password!")
os.sleep(2)[/indent]
[indent=1]end[/indent]
end
function button()
[indent=1]event = os.pullEvent()[/indent]
[indent=1]if event == "redstone" and rs.getBundledInput("bottom") == 1 then[/indent]
[indent=2]rs.getBundledOutput("bottom", 0)
os.sleep(5)
rs.getBundledOutput("bottom", 2048)[/indent]
[indent=1]end[/indent]
end
while true do
[indent=1]parallel.waitForAny(pwd(), button())[/indent]
[indent=1]if t == "system" then break end[/indent]
end
I know their is a bit to clean up, but first it has to work.
As you see I tried to work with the parallel class, but I don't quite get how it works.
I would be nice if someone could help here and for later clean up, is it possible to assign return values, if a function is called by waitForAny/All?
I do have quite a bit of programming experience (although not in lua) but I never had to use multitasking.
Spoiler
function pwd()[indent=1]term.clear()
term.setCursorPos(1,1)
print("Please enter password:")
t=read("*")[/indent]
[indent=1]
if t == "chamber" then[/indent]
[indent=2]rs.setBundledOutput("bottom", 0)
os.sleep(5)
rs.setBundledOutput("bottom", 2048)[/indent]
[indent=1]else[/indent]
[indent=2]print("Wrong password!")
os.sleep(2)[/indent]
[indent=1]end[/indent]
end
function button()
[indent=1]event = os.pullEvent()[/indent]
[indent=1]if event == "redstone" and rs.getBundledInput("bottom") == 1 then[/indent]
[indent=2]rs.getBundledOutput("bottom", 0)
os.sleep(5)
rs.getBundledOutput("bottom", 2048)[/indent]
[indent=1]end[/indent]
end
while true do
[indent=1]parallel.waitForAny(pwd(), button())[/indent]
[indent=1]if t == "system" then break end[/indent]
end
I know their is a bit to clean up, but first it has to work.
As you see I tried to work with the parallel class, but I don't quite get how it works.
I would be nice if someone could help here and for later clean up, is it possible to assign return values, if a function is called by waitForAny/All?