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

[Question] How does rednet.api work

Started by rdsn, 31 March 2012 - 08:13 PM
rdsn #1
Posted 31 March 2012 - 10:13 PM
I am getting pretty familiar with computercraft but I don't understand rednet. How does rednet transfer signal over bundled cable? Through a specific coloured wire or over the bundled cable itself. Do the bundled cable from both machines have to be connected to each other. Is there a range like redstone dust in vanilla minecraft. Also, what does rednet.annouce do, what do you mean by broadcast empty rednet message. What happens if two computers broadcast over the same wire at the same time, will it be any different if it is a private .send message. Lastly, how do I turn a message recieved over rednet into a variable. I know I have a lot of questions but thanks.

Edit: Sorry, two more questions
Why doesn't two pullevents work in the same script? (As in 1st pull event, returns values, second pull event, broken.)
How do I permenantly save variables so that the same value is assigned to the variable no matter what I do to the computer.
Advert #2
Posted 31 March 2012 - 10:34 PM
I am getting pretty familiar with computercraft but I don't understand rednet. How does rednet transfer signal over bundled cable? Through a specific coloured wire or over the bundled cable itself.
Using rednet.open/send will use the entire bundled cable (i.e, all the colors).
It transfers it by toggling specific colors on/off. You can see the code if you find the rednet API file.

Do the bundled cable from both machines have to be connected to each other.
Yes, since it uses the bundled cable to transfer data. It does not just magically find the end and send a message, and is quite slow.
I'd recommend using wireless modems, if you can.

Is there a range like redstone dust in vanilla minecraft.
It has the same limitations that bundled wire in RP2 does, which I believe is around 256 blocks of wire.

Also, what does rednet.annouce do, what do you mean by broadcast empty rednet message.
Preicely that, an empty message is sent, with the target being every other computer connected.
What happens is that all the other computers can see that that computer is connected via the cable.

What happens if two computers broadcast over the same wire at the same time, will it be any different if it is a private .send message.
Two computers can't transmit at the same time on the same bundled cable, since they use the cable itself and not magic.
There is no difference between prvate (.send) and broadcasted (.broadcast) messages, except that the computers will see that the message is not for them, and discard it.

Lastly, how do I turn a message recieved over rednet into a variable. I know I have a lot of questions but thanks.
You can't turn it into a variable, but you can store the data that was transmitted.
See help events, and the function rednet.receive().

Here's a sample:

rednet.open("back") -- assumes you're connected from the back
local id, message = rednet.receive()
print("From: ", id, ", Message: ", message)

Edit: Sorry, two more questions
Why doesn't two pullevents work in the same script? (As in 1st pull event, returns values, second pull event, broken.)
I can't help you with this without seeing what you are doing with your code; please post it if you can.

How do I permenantly save variables so that the same value is assigned to the variable no matter what I do to the computer.

You'll need to save the value to a file, then re-load it.

There are a few APIs that let you do this in the Program Library/APIs forum.
rdsn #3
Posted 31 March 2012 - 10:52 PM
Can I tell the program to use only specific colour(s) to transfer data? That way I can use a specific coloured wire to filter out other signals in the wire.
.send does not interfere with other computers connected to the network but not the recepient of the message, correct?
Are rednet messages actually redstone signals which can interfere with other devices?
Advert #4
Posted 31 March 2012 - 10:56 PM
Can I tell the program to use only specific colour(s) to transfer data? That way I can use a specific coloured wire to filter out other signals in the wire.
.send does not interfere with other computers connected to the network but not the recepient of the message, correct?
Are rednet messages actually redstone signals which can interfere with other devices?
Not in a way that I know of.

No. If any computer is transmitting on a bundled cable, then you cannot transfer to any other computer on that bundle.

Yes, this is what I said in my post.
rdsn #5
Posted 31 March 2012 - 11:00 PM
Ok I guess I will need to rethink trying to use an existing bundled wire connected to several on/off devices as a rednet wire. Thanks for your help.
Advert #6
Posted 31 March 2012 - 11:02 PM
Ok I guess I will need to rethink trying to use an existing bundled wire connected to several on/off devices as a rednet wire. Thanks for your help.

You're welcome.
I'd recommend using wireless modems, instead of bundles. They have a range of 64/16(storm), and you're not limited in the amounts of message you can send, and they send the message instantly.
rdsn #7
Posted 01 April 2012 - 09:31 PM
How do I make the pullEvent command read the message that triggers the rednet pullEvent?
Advert #8
Posted 01 April 2012 - 10:26 PM
You'd use a loop. If you take some time to search through the forums, you will find plenty of examples.