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

Rednet.receive

Started by popdog15, 02 January 2013 - 05:25 PM
popdog15 #1
Posted 02 January 2013 - 06:25 PM
I want to have a turtle always be open for a certain signal, waiting for it, though still be ready for normal tasks. Normally, it just has the normal command line, though, you can not type / assign programs. Is there anyway to have a program "running in the background" still waiting to receive a message while being able to perform the tasks you want it to?
remiX #2
Posted 02 January 2013 - 07:53 PM
Yes, take a look at the parallel API


function listen()
	while true do
	  senderid, message = rednet.receive()
	  print(message)
	end
end

function OtherFunctions()
--Code
end

--More code!
parallel.waitForAny(listen, OtherFunctions) -- waitForAny will stop if any of the functions return,
parallel.waitForAll(listen, OtherFunctions) -- waitForAll will stop only when all functions have returned
popdog15 #3
Posted 03 January 2013 - 07:39 AM
@remiX Though do you know if there is a way instead of using it to run multiple functions in a single program, use the default OS whilest a program is running, without you interacting with it? (That of which is still waiting for an rednet input)
remiX #4
Posted 03 January 2013 - 08:04 AM
Default OS? Are you talking about the shell with "> " and you can type in programs?
popdog15 #5
Posted 03 January 2013 - 10:05 AM
Yes
remiX #6
Posted 03 January 2013 - 10:31 AM
The only way I can think of is if you make your own shell within the program where you can open programs and such