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

making a computer react to the content of rednet messages?

Started by minecrash, 07 April 2012 - 02:04 PM
minecrash #1
Posted 07 April 2012 - 04:04 PM
hello, i want to make a computer react to the content of a received rednet message but whenever i try to make something like a = rednet.receive() does a change to the computer ID from which the message came from instead of the message itself.

how can i make a the received message?
1v2 #2
Posted 07 April 2012 - 04:17 PM
Use id, message = rednet.receive()
minecrash #3
Posted 07 April 2012 - 05:11 PM
doesnt work.
however i got something to work with
rednet.receive()
a = rednet_message
but it seems that rednet_message stays on the first received message even when i restart the script or send a different message.
Wolvan #4
Posted 07 April 2012 - 05:18 PM
doesnt work.
however i got something to work with
rednet.receive()
a = rednet_message
but it seems that rednet_message stays on the first received message even when i restart the script or send a different message.
It is like this
id, text = rednet.receive()
if text == THE_TEXT_IT_SHOULD_RESPOND_TO then
do_something()
end
minecrash #5
Posted 07 April 2012 - 08:09 PM
i feel stupid to have to ask this but what is id supposed to be? tried the computer id but that didnt work.
Wolvan #6
Posted 07 April 2012 - 08:17 PM
the functionrednet.receive() returns 2 values:
the first value (in my example) is the computer ID of then SENDER So if computer with id 1 sends to computer with id 2 the first value would be 1
the second value is the received text as a string
minecrash #7
Posted 07 April 2012 - 08:55 PM
when i enter the ID of the sender do i get an unexpected symbol error.

the script:
2, test = rednet.receive()
if test == testmsg then
print("succes")
else
end
kamnxt #8
Posted 07 April 2012 - 09:54 PM
The function returns the id of the sender computer.

id, message = rednet.receive()
This will work. ^
This will not. v

2, message = rednet.receive()
2 is not a variable, but id is.
Wolvan #9
Posted 08 April 2012 - 01:23 AM
You don't have to enter the sender's ID. The rednet function automatically sets the id. You could change the name "id" to for example "peter" and it would still work.
Example:

THE IDs ARE JUST MADE UP!


Computer 1(Sender) (ID: 5)

rednet.broadcast("Hello World") --Sends this message to all computers in range

Computer 2(Receiver) (ID: 8)

id, message = rednet.receive()
print("Computer "..id.." sent:n"..message) -- Printing (n is a new line)

(or change the receiver as suggested)


peter, message = rednet.receive()
print("Computer "..peter.." sent:n"..message) -- Printing (n is a new line)


would output:

Computer 5 sent:
Hello World


Let me try something: If I helped you don't forget to click the green arrow at the right bottom corner :P/>/>
minecrash #10
Posted 08 April 2012 - 11:33 AM
got it to work :D/>/>

Let me try something: If I helped you don't forget to click the green arrow at the right bottom corner :P/>/>

what is that button supposed to do anyway? other than being a thumbs up for forum posts.
Wolvan #11
Posted 08 April 2012 - 01:03 PM
got it to work :)/>/>

Let me try something: If I helped you don't forget to click the green arrow at the right bottom corner :P/>/>

what is that button supposed to do anyway? other than being a thumbs up for forum posts.
I know just testing if someone clicks it :D/>/>