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

parallel function loop

Started by tfoote, 24 June 2012 - 10:38 PM
tfoote #1
Posted 25 June 2012 - 12:38 AM
So i looked this up in the wiki and i still have a question. I am making this server thing and i need the 1 computer to do multiple functions. I am using the parallel api and was wondering if this code is possible…

function 1()
while true do
...
end
end
function 2()
while true do
...
end
end
parallel.waitForAny( 1(), 2() )
MysticT #2
Posted 25 June 2012 - 12:44 AM
Almost, you don't have to call the functions, and function names can't be just numbers.

local function f1()
  while true do
    ...
  end
end

local function f2()
  while true do
    ...
  end
end

parallel.waitForAny(f1, f2)
Also, you can have as many functions as you want.
tfoote #3
Posted 25 June 2012 - 12:51 AM
and so i can have several functions that never end?
MysticT #4
Posted 25 June 2012 - 12:52 AM
Yes, just remember to add a yield (os.pullEvent or something like that) to the functions.
tfoote #5
Posted 25 June 2012 - 12:52 AM
OK! there will be plenty of that