Is there any way I can make a computer wait for a response from another computer? I know how to send a bunch of information from one computer to another, but what I want is a computer listening for a certain phrase to do something. Can I do this?
2
6 replies to this topic
#1
Posted 01 July 2014 - 11:37 PM
#2
Posted 02 July 2014 - 10:14 AM
to have a computer receive a message you should do:
id,message=rednet.receive()
#3
Posted 03 July 2014 - 02:50 PM
That is for rednet though, right? I'm talking about wireless modems, if it make any difference. Sorry if it does make a really big difference.
#4
Posted 03 July 2014 - 02:51 PM
The rednet API uses wireless and wired modems.
#5
Posted 03 July 2014 - 05:34 PM
Ok... Thanks, I guess... but will the line for receiving messages in the modem API wait for a message?
#6
Posted 03 July 2014 - 05:39 PM
Yes, it will wait untill it receives a message, however you could specify a timeout as first argument
for example:
for example:
id,message=rednet.receive(1)This would wait for a message for 1 second, if there is none both id and message will be nil and it will move on.
#7
Posted 03 July 2014 - 08:08 PM
You also want to make sure your modem is open, otherwise it would be useless to wait for a message
Now you can check what the variable 'message' was equal to
rednet.open( "<SIDE>" )and then to listen( as said above )
local id, message = rednet.receive()
Now you can check what the variable 'message' was equal to
if message == "Hello" then print( "Hello!" ) end
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users