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

Parallel API and function arguments

Started by tball146, 14 April 2016 - 06:16 PM
tball146 #1
Posted 14 April 2016 - 08:16 PM
okay so i have been messing around with the parallel api or however its spelt so i expiremted an i came across the issue of not being to use arguements any idea how to??
Edited by
KingofGamesYami #2
Posted 14 April 2016 - 08:26 PM
Wrap the function call in a function.

function() read(*) end
tball146 #3
Posted 15 April 2016 - 08:47 AM
okay uhhm dont get it..

i tried

parallel.waitForAll(task1(arg here),task2(arg here))
Edited on 15 April 2016 - 06:51 AM
Bomb Bloke #4
Posted 15 April 2016 - 09:10 AM
You have to pass the API function pointers. It then executes the functions they point to. What you're doing is calling your functions, and then attempting to pass whatever they return to the API.

Try it like this:

local function wrapper1()
  task1(arg here)
end

local function wrapper2()
  task2(arg here)
end

parallel.waitForAll(wrapper1, wrapper2)  --# Note the lack of brackets after wrapper1 / wrapper2
tball146 #5
Posted 15 April 2016 - 09:37 AM
okay thanks
Lupus590 #6
Posted 15 April 2016 - 01:22 PM
what KingofGamesYami did was define an anonymous function which you would use like so:

 parallel.waitForAll(function() read(*) end, someOtherFunctionPointer)
  --# someOtherFunctionPointer could also be another anonymous function 
Edited on 15 April 2016 - 11:23 AM