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

[Lua] Rednet Message

Started by lieudusty, 20 July 2012 - 04:48 AM
lieudusty #1
Posted 20 July 2012 - 06:48 AM
Hi everyone! :P/>/>

I'm trying to make a program where if it gets the right message from another computer it will return with "Message received!".
But when I try:

rednet.open("left")
state = rednet.receive(10)
if state == "clock" then
  print("Message received!")
end
it doesn't work. Can someone please help?
MysticT #2
Posted 20 July 2012 - 04:40 PM
rednet.receive returns 3 values: the id of the sender, the message and the distance from the sender. To use the message, you need to store it in a variable. You only stored the id.
Fixed code:

rednet.open("left")
local id, state = rednet.receive(10)
if state == "clock" then
  print("Message Received!")
end
lieudusty #3
Posted 20 July 2012 - 05:20 PM
Thank you so much! I've been confused by this for a while.