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

How to run two functions at the same time

Started by TNT_Nolan, 27 April 2016 - 07:23 PM
TNT_Nolan #1
Posted 27 April 2016 - 09:23 PM
Hello, I am trying to make a script that can do rednet.recieve() while typing a message. Anybody know how to do this?
Lupus590 #2
Posted 27 April 2016 - 09:35 PM
quicker to code but slower to run way: http://www.computerc...allel_%28API%29

quicker to run but harder to code way: pull events with no filter and then identify the event, if char then replicate the read function, if rednet then do thing with message, else ignore
Edited on 27 April 2016 - 07:36 PM
Morganamilo #3
Posted 28 April 2016 - 01:29 AM
quicker to code but slower to run way: http://www.computerc...allel_%28API%29

quicker to run but harder to code way: pull events with no filter and then identify the event, if char then replicate the read function, if rednet then do thing with message, else ignore

A little off topic but it can be quite useful to rewrite the pullEvent function to take multiple arguments.


os.pullEvent("key", "rednet_message")
Dragon53535 #4
Posted 28 April 2016 - 01:31 AM
But why? You have to differentiate between one event or the other anyways, why not just have a no arg os.pullEvent call?
Morganamilo #5
Posted 28 April 2016 - 02:13 AM
But why? You have to differentiate between one event or the other anyways, why not just have a no arg os.pullEvent call?

You no longer have to loop os.pullEvent() until you get the event you want. Instead os.pullEvent("key", "char") will wait for one of those events.
Bomb Bloke #6
Posted 28 April 2016 - 02:33 AM
The catch there is that "typing a message" relies on more than one keypress. You're going to have to loop it either way.