Posted 22 September 2012 - 05:27 PM
Whe, I try to use the parallel API to run multiple functions, only the first one starts and not the other one. How can I fix this ?
There is my code :
There is my code :
Spoiler
shell.run("monitor", "top", "clear")
shell.run("clear")
mag = peripheral.wrap("left")
term.redirect(peripheral.wrap("top"))
function wpass() -- write the password in the magnetic card and in a file
write("enter password : ")
pass = read("*")
local passfile = fs.open("test.txt", "a")
passfile.writeLine(pass)
passfile.close()
print("Please insert a magnetic card in the device.")
mag.beginWrite(pass, "Access card")
wtest = mag.isWaiting()
print(wtest)
end
function passtest() -- test the password on the card
mag.setInsertCardLight(true)
passfile = fs.open("test.txt", "r")
local pass = {}
local line = passfile.readLine()
repeat
table.insert(pass, line)
line = passfile.readLine()
until line == nil
passfile.close()
while true do
repeat
event, data = os.pullEvent()
until event == "mag_swipe"
if data == pass[1] then
mag.setInsertCardLight(false)
print("password ok")
rs.setOutput("right", true)
sleep(5)
rs.setOutput("right", false)
event = nil
data = nil
else
print("password incorect")
event = nil
data = nil
end
end
end
function input() -- for input some commands
term.restore()
input = read()
if input == "password" then
wpass()
else
print("error")
sleep(1)
shell.run("clear")
input()
end
end
parallel.waitForAll(passtest(), input())