how can i make a the received message?
This is a read-only snapshot of the ComputerCraft forums,
taken in April 2020.
making a computer react to the content of rednet messages?
Started by minecrash, 07 April 2012 - 02:04 PMPosted 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?
how can i make a the received message?
Posted 07 April 2012 - 04:17 PM
Use id, message = rednet.receive()
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.
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.
Posted 07 April 2012 - 05:18 PM
It is like thisdoesnt 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.
id, text = rednet.receive()
if text == THE_TEXT_IT_SHOULD_RESPOND_TO then
do_something()
end
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.
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
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
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
the script:
2, test = rednet.receive()
if test == testmsg then
print("succes")
else
end
Posted 07 April 2012 - 09:54 PM
The function returns the id of the sender computer.
This will not. v
id, message = rednet.receive()
This will work. ^This will not. v
2, message = rednet.receive()
2 is not a variable, but id is.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)
Computer 2(Receiver) (ID: 8)
(or change the receiver as suggested)
would output:
Let me try something: If I helped you don't forget to click the green arrow at the right bottom corner :P/>/>
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/>/>
Posted 08 April 2012 - 11:33 AM
got it to work :D/>/>
what is that button supposed to do anyway? other than being a thumbs up for forum posts.
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.
Posted 08 April 2012 - 01:03 PM
I know just testing if someone clicks it :D/>/>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.