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

Multiple non-terminating functions at once

Started by Kizz, 11 July 2014 - 01:07 PM
Kizz #1
Posted 11 July 2014 - 03:07 PM
Hey guys,

I am curious, I know parallel can run two functions at once, but it doesn't seem to do well running two non-terminating functions, IE:


function input()
    choice=io.read()
    choice=choice+1-1
    print(choice)
end

function get()
    rednet.receive() 
end

parallel.waitForAll(input(),get())


This program will only move on to the get() function once it has gathered user input.

What I'd love to do is listen in the background while I was getting user input.

In conventional computing this is done through multiple programs.

But I can't seem to find a way to run two processes at once in CC.

Is this possible? Is there some other way of doing this that I'm missing?
Lyqyd #2
Posted 11 July 2014 - 03:21 PM
You're calling each function in turn, then passing the results to the parallel call. You need to pass the functions themselves, so remove the parentheses from each function name in the parallel call's arguments.
Cranium #3
Posted 11 July 2014 - 03:25 PM
silly Lyqyd, forgot to approve this post :3
Kizz #4
Posted 11 July 2014 - 03:29 PM
Holy carpfish… how could I go this long and not know this :o/>

Thanks a lot guys!