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

simple rednet tutorial

Started by NanoBob, 01 May 2013 - 02:07 PM
NanoBob #1
Posted 01 May 2013 - 04:07 PM
so….
I guess you are intrested in finding out how rednet works.

First of all, you need a wireless modem, you craft them by surounding a redstone torch in stone in a crafting table.

So you will ofcourse also need a computer and/or turtle.

Once you've got that you are ready to program.

So first things first you have to open the wireless modem.
You will have to type (either type lua or edit a program)
rednet.open("right") --- this can also be left/top/bottom/back/front
Then you will have to choose, do you want to broadcast? (sends a message to all computers in range)
Do you want to send? (send a message to a specific computer)
Or do you want to receive a message from a different pc/turtle.

So first off I will explain you what you do if you are on the transmitting end

So you do
rednet.send(ID,"message")
or
rednet.broadcast("message")
So… first off: rednet.send
You will have to use
rednet.send(ID,"message")
The ID is the computer id you want to send the message to, you can find this by typing id in a computer on turtle.
Then you type your message, what should this be? Whatever you want…. do you want to type random shiz? do
rednet.send(ID,"random shiz")
So this is all you have to do on the sending side.

Next up!
rednet.broadcast()
This basicly does the exact same thing except you can leave out the ID because it will send it to every computer wich is receiving.

Now the receiving side.

Basicly you want to do
id,message=rednet.receive() --- This WILL wait until you get a message you can't do anything in the meantime.
Id is the id from the computer who send you send the message.
And message is the message the other computer send.
So if you want to only accept messages from a specific pc, you can do for example:

if
  id==(ID you want to accept from)
then
  the random code you want to do
else ---(optional)
end

If you want to accept messages from any id, you can just do nothing with the id.
So… now you get a message.. so? what do we do with it?
First off, what do you want to do with it?
Example:
You want to make a chat system.
do print(message)

example2:
Do you want a program with the same name as the message
do
shell.run(message)

example3:
Do you want the computer to do something ONLY if you get that specific message?
do
if
  message==("COOKIES") --- cookies may be anything you want
then
  do some random code
else -- (optional)
end

So…. I guess this is it?
If you want to know anything ask me in the comments
Dlcruz129 #2
Posted 01 May 2013 - 11:14 PM
Please use capitalization. Also, code looks much nicer if you encase it in [*CODE] tags. Just type [*CODE]im a code[*/CODE] without the *s

i am code.
Spongy141 #3
Posted 02 May 2013 - 12:14 AM
Do what Dlcruz said, and while at it, try to indent, it makes your code look neater, and easier for people to read.
NanoBob #4
Posted 02 May 2013 - 03:35 AM
Will do that as soon as i get to a computer
NanoBob #5
Posted 02 May 2013 - 06:31 AM
Done it, Did anyone find this usefull?
Dlcruz129 #6
Posted 02 May 2013 - 10:14 AM
Done it, Did anyone find this usefull?

I've been with ComputerCraft since last August, so I didn't find it useful, but I think this is helpful for new users. :P/>