Jump to content




Wireless Modems and listening

wireless networking api

6 replies to this topic

#1 Dmac9244

  • Members
  • 8 posts

Posted 01 July 2014 - 11:37 PM

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 NanoBob

  • Members
  • 102 posts

Posted 02 July 2014 - 10:14 AM

to have a computer receive a message you should do:
id,message=rednet.receive()


#3 Dmac9244

  • Members
  • 8 posts

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 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 03 July 2014 - 02:51 PM

The rednet API uses wireless and wired modems.

#5 Dmac9244

  • Members
  • 8 posts

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 NanoBob

  • Members
  • 102 posts

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:
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 TheOddByte

    Lazy Coder

  • Members
  • 1,607 posts
  • LocationSweden

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 :P
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