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

[SOLVED]Parallel API, bug ?

Started by flighteur, 22 September 2012 - 03:27 PM
flighteur #1
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 :

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())
MysticT #2
Posted 22 September 2012 - 06:02 PM
You have to pass the functions as arguments, not call them.

parallel.waitForAny(function1(), function2()) -- wrong
parallel.waitForAny(function1, function2) -- ok
flighteur #3
Posted 22 September 2012 - 06:18 PM
thanks