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

[1.3] How To Use Modems (Rednet)

Started by Casper7526, 26 February 2012 - 02:01 AM
Casper7526 #1
Posted 26 February 2012 - 03:01 AM
[As of ComputerCraft 1.5, this information may be out of date, in part or in whole. Read and use accordingly. -L]

OK.. so you've got 1.3 and now your thinking to yourself… I wanna use this modem… I wanna create the internet in minecraft!!!!

Lets take it back a few steps and first learn all about the modem and how to use it in a basic way.

The first thing you should know is that to attach the modem to a computer you must sneak first then right-click on the side of the computer you would like to attach the modem too.

Turtles with modems automatically have them placed on the right side when crafted.

So now that we have 2 computers or a computer and a turtle setup with modems we are going to learn how to pass information between them.

Computer 1:

rednet.open("right")
This command opens the port of the modem. The "right" statement is the side of the computer that the modem is located.

rednet.broadcast("Our information")
This command says that we want to broadcast the string "Our Information" to every modem within range. Anyone that is listening for information will receive our statement.

Turtle 1:

rednet.open("right") 
Once again, we have to open up the port on the modem so that we can communicate, luckily turtle's always have their modems placed on the right side.

id, message  = rednet.receive(10)
This command makes the computer listen to the modem for 10 seconds. You could simply do () instead of (10) and it would listen indefinitely until it received communication. The rednet.receive function returns us 2 variables when it receives information. The ID of the computer that sent the information and the message itself.

print ("Computer ".. id .. " has sent us a message")
print ("The message is")
print (message)
This is just some output information so we can see who sent us something and what that something was.

Now that's all fine and dandy, but we don't want all those computers getting our information, thats just wrong, we don't wanna share our private data with everyone. So this time instead of using the rednet.broadcast command we will be using the rednet.send command.

Computer 1:

rednet.open("right")
rednet.send(5, "Our Information")
This will open the port like normal, and then it will send information but it will only send that information to Computer/Turtle #5 (you can see the ID of a computer or turtle by typing "id" inside your computer or turtle)

So now we have to make sure we use Computer or Turtle #5 to receive our information and we can do the same script as above.


I hope this gets everyone on their way to using modems successfully, I understand it's a brief tutorial, but your goal is to manipulate everything you learned here into something amazing :)/>/>/>

If you need more help on anything in computercraft at anytime you can simply type "help index" inside your computer and it will show you an index of all the help files that are available. One of them happens to be "help rednet" which explains some more of the functions you have access to.
Bennievv #2
Posted 26 February 2012 - 07:45 AM
Thanks! Now I know how it works :)/>/>
Pizmovc #3
Posted 28 February 2012 - 08:49 PM
Thanks!
Now I'm interested in sending a program/file to my turtle… So it can start working for me!
Casper7526 #4
Posted 28 February 2012 - 08:49 PM
Well just remember you can only send strings, so basically you would save your program file into a string then turn it back into a file on the other end :D/>/>
Pizmovc #5
Posted 28 February 2012 - 09:10 PM
I thought about that, but it seemed like there has to be a better way!

How would I go about doing that? I can't just do x = MyProgram right?
MysticT #6
Posted 28 February 2012 - 09:18 PM
How would I go about doing that? I can't just do x = MyProgram right?
You have to do open the file, read all and send it.
Something like this:

local file = fs.open("Your/file/path", "r")
if file then
    local sFile = file.readAll()
    rednet.send(ID, sFile)
    file.close()
end
Pizmovc #7
Posted 28 February 2012 - 09:41 PM
Awesome! This now works!
Now all I need to do is save it to file! Thanks!
Brilliantos #8
Posted 01 March 2012 - 01:32 AM
Hi, ive gotten all this working, my turtle can recieve commands from my Pc. My problem is there are other people broadcasting commands which are messing with my turtle. I would like to know if it is possible for the turtle to only recieve commands from my Pc
Thanks :unsure:/>/>
Espen #9
Posted 01 March 2012 - 01:48 AM
Yes, that is possible, in a way.
It will always 'see' all messages, even the ones from other computers.
But you can tell it to only listen for messages coming from your computer ID.

If you're using rednet.receive( timeout ) to listen for incoming messages, then ignore all messages whose id does not match the one from your sending computer, e.g.:

local allowedComputerID = 5

local id, msg = rednet.receive(10)
if id == allowedComputerID then
  print( msg )
end

If you're using the event-method, then you do the same:

local allowedComputerID = 5

local sEvent, param1, param2 = os.pullEvent()

if sEvent == "rednet_message" and param1 == allowedComputerID then
  print( param2 )
end

Disclaimer: That's all from the top of my head and thus untested in-game. Should work though.
Fix: Changed local allowedComputerID = 5 to local allowedComputerID = "5"
Edited on 01 March 2012 - 01:58 PM
6677 #10
Posted 01 March 2012 - 10:57 AM
For some reason

rednet.recieve()
returns an error about attempting to call nil. It does this when I add a parameter as either an integer or string aswell.

I prefer to use events anyway but I can't see why it won't work.
Espen #11
Posted 01 March 2012 - 11:24 AM
That is because there is no rednet.recieve().
You mistyped it, it's actually rednet.receive(). :unsure:/>/>

In general: attempt to call nil
Brilliantos #12
Posted 01 March 2012 - 02:05 PM
Hmm i tried what you said in game and it keeps telling me it is expecting 'then' even though i have put the then in the right place
Espen #13
Posted 01 March 2012 - 02:29 PM
Hmm i tried what you said in game and it keeps telling me it is expecting 'then' even though i have put the then in the right place
Can you post your code or a thread where you maybe posted it already?
It'd be a lot easier to pinpoint your problem then. :unsure:/>/>
Brilliantos #14
Posted 01 March 2012 - 02:40 PM
Its fine i got it working you just forgot the "" around AllowedComputerID :unsure:/>/>
Espen #15
Posted 01 March 2012 - 02:52 PM
Its fine i got it working you just forgot the "" around AllowedComputerID :unsure:/>/>
Ah, I see what you mean, I defined allowedComputer as a number instead of a string.
Thought the rednet_message event would return the ID as a number, not a string.
Thx, will fix the code above.


Wait a minute, something isn't right. It should return a number, will test this in-game now…

Edit: Ok I tried it in-game now and it works fine for me, so you must've done something wrong.
The only tings I didn't include were the call to rednet.open and a loop, because I only wanted to show the principals and assumed you would integrate it into your program anyway.
So perhaps that is what might've given you problems?
Just to be sure here's the code within a loop, incl. the rednet.open call:
local nAllowedComputerID = 1	-- Change this number to the ID of your sending computer.
local sSide = "back"	-- Change this to the side of your receiving computer, where messages are coming in.

rednet.open( sSide )	-- Open the rednet-port on side 'sSide'
while true do
  local sEvent, param1, param2 = os.pullEvent()	-- Listen for events and two of their parameters.

  if sEvent == "rednet_message" and param1 == nAllowedComputerID then
	print( param2 )
  end

  if sEvent == "char" and param1 == "q" then break end	-- Pressing q stops the program.
end

rednet.close( sSide )	-- Close the rednet-port on side 'sSide'
Edited on 01 March 2012 - 02:16 PM
mrgreaper #16
Posted 02 March 2012 - 03:05 AM
ok im completly stuck

i have a terminal written in 1.2 that just asks for a password to then activate our bases light system, as we have grown we keep having to run to this terminal to do the command so with 1.3 and modems all our prayers are answered how ever its not working

function os.pullEvent()
local sEvent, param1, param2, event, p1, p2, p3, p4, p5 = os.pullEventRaw()
if event == "terminate" then
os.reboot()
end
if sEvent == "rednet_message" and param1 == 144 and param2 == 54 then
rs.setOutput("bottom", true)
sleep(1)
rs.etOutput("bottom", false)  
end
return event, p1, p2, p3, p4, p5
end
function pass()
term.clear()
term.setCursorPos( 1, 1 )
print ("Base Lockdown disengage system")
print ("Enter Authorisation to unlock and light up")
t = read("*")
write ("> ")
if t == "lettherebelight" then
rs.setOutput("bottom", true)
sleep(1)
rs.setOutput("bottom", false)
pass()
elseif t == "sillypc" then
term.clear()
term.setCursorPos( 1, 1 )
print ("PRROGRAM TERMINATED")
shell.run"shell"
else
pass()
end
end
pass()
(its 0302 and it took me 20 minutes to copy what was on my screen to this so the odd grammer error may or may not be just a typo, its on our server and with out abusing admin powers i dont have access to the computer folder (and ctrl c ctrl v dont work in the editor :unsure:/>/> (anyone know how to add ctrl+c or +v will be my hero))
as you can see its a modified tutorial script, i added the anti ctrl+t code, and masked the input.

now what i want it to do is function as it has always done but if it hears a code from terminal 144 that says 54 it should power up the base, now since the ctrl + t code is working even if the program is waiting for input it seemed logical to add the listen code there so using the example further up i added the veriables in

running this it sticks before the input command so it cant do anything (it disables ctrl + t nicely lol had to put a discdrive next to it to gain access lol)

so what did i do wrong?


edit retyping out the code helped
return event, p1, p2, p3, p4, p5 should be return sEvent, param1, param2, event, p1, p2, p3, p4, p5
and it may help if i turn the modem on lol
remlly #17
Posted 03 March 2012 - 03:30 PM
ok, can somebody help, if i typ rednet.open('''right'') its says no such program. i have craftos 1.3
Espen #18
Posted 03 March 2012 - 03:38 PM
ok, can somebody help, if i typ rednet.open('''right'') its says no such program. i have craftos 1.3
That's because rednet.open() is a call to a function and not a program.
You can't call funtions directly from the shell, you'll either have to create a program and write it in there, or you go into the Lua interactive shell.
The latter can be started by typing "lua". Your command prompt will then change to "lua>" and then you can call rednet.open("right").
remlly #19
Posted 03 March 2012 - 03:50 PM
i''ll try…
edit, nope. if i typ rednet.open(''back'')'i get :27: [string ''lua'']:1: expected, i dont know waht this means

and the same on the turtle but at the end unexpected symbol
Espen #20
Posted 03 March 2012 - 04:09 PM
i''ll try…
edit, nope. if i typ rednet.open(''back'')'i get :27: [string ''lua'']:1: expected, i dont know waht this means

and the same on the turtle but at the end unexpected symbol
Ahh, now I see your problem.^^
You're not using double-quotes, but two single-quotes instead.
Use two double-quotes " instead of two single-quotes ''
The former is one character and the latter is two characters.
remlly #21
Posted 03 March 2012 - 04:13 PM
i''ll try…
edit, nope. if i typ rednet.open(''back'')'i get :27: [string ''lua'']:1: expected, i dont know waht this means

and the same on the turtle but at the end unexpected symbol
Ahh, now I see your problem.^^
You're not using double-quotes, but two single-quotes instead.
Use two double-quotes " instead of two single-quotes ''
The former is one character and the latter is two characters.
youre messing with my brain!!!!! 2 quotes singel quotes, wahts the differnet. is it this '' or this ' or ' '
MysticT #22
Posted 03 March 2012 - 04:55 PM
i''ll try…
edit, nope. if i typ rednet.open(''back'')'i get :27: [string ''lua'']:1: expected, i dont know waht this means

and the same on the turtle but at the end unexpected symbol
Ahh, now I see your problem.^^
You're not using double-quotes, but two single-quotes instead.
Use two double-quotes " instead of two single-quotes ''
The former is one character and the latter is two characters.
youre messing with my brain!!!!! 2 quotes singel quotes, wahts the differnet. is it this '' or this ' or ' '
You are using two single-quotes ('), you have to use double-quotes ("). Use rednet.open("back") instead of rednet.open(''back'').
Espen #23
Posted 03 March 2012 - 04:59 PM
youre messing with my brain!!!!! 2 quotes singel quotes, wahts the differnet. is it this '' or this ' or ' '
Lol, sorry to mess with your brain. :unsure:/>/> When I wrote " and '' I just wanted to tell you the difference between ONE double-quote and TWO single-quotes. It's a bit hard to emphasize it when they look so much alike, but MysticT did a good job with the coloring. B)/>/>
remlly #24
Posted 03 March 2012 - 05:10 PM
i cant see the different, is it a other key, OMN i am stuck. so its ''back'' or ' 'back' '
edit got it! its ", i just needed to hold the shift button :unsure:/>/>
double edit: mmh attempt to index ? (a nil value) what does this mean?
third edit': i typed open.rednet while tis rednet.open B)/>/>
remlly #25
Posted 03 March 2012 - 05:44 PM
ok well, now i need help with receive, so i typ 23, message = rednet.receive(10)

i am doing something wrong
MysticT #26
Posted 03 March 2012 - 05:49 PM
rednet.receive() returns 2 values, sender ID and the message.
You have to save those values in variables, something like this:

local id, msg = rednet.receive(10)
If you want to receive from a particular id, you receive the messages and then check the sender id. (I suppose you wanted to do that)
A simple example:

local id, msg = rednet.receive(10)
if id == 23 then
    print(msg)
end
remlly #27
Posted 03 March 2012 - 05:53 PM
rednet.receive() returns 2 values, sender ID and the message.
You have to save those values in variables, something like this:

local id, msg = rednet.receive(10)
If you want to receive from a particular id, you receive the messages and then check the sender id. (I suppose you wanted to do that)
A simple example:

local id, msg = rednet.receive(10)
if id == 23 then
	print(msg)
end
so i have to do: edit recieve, typ your code. and then launch recieve as program (i never used Lua :unsure:/>/> )
ENET #28
Posted 06 March 2012 - 11:45 PM
The print takes indefinite amount of args.


print ("Computer ".. id .. " has sent us a message")
print ("The message is")
print (message)

Can be….


print ("Computer ".. id .. " has sent us a message\n", "The message is\n", message);
And it will make less calls to the lua parser.
Advert #29
Posted 07 March 2012 - 12:01 AM
The print takes indefinite amount of args.


print ("Computer ".. id .. " has sent us a message")
print ("The message is")
print (message)

Can be….


print ("Computer ".. id .. " has sent us a message\n", "The message is\n", message);
And it will make less calls to the lua parser.

Further improving on that, you can replace the ".." with ",", to reduce concatenation:


print ("Computer ", id, " has sent us a message\n", "The message is\n", message)


Also, print() is defined in Lua (for CC):

bios.lua, line 91-98:

function print( ... )
 local nLinesPrinted = 0
 for n,v in ipairs( { ... } ) do
  nLinesPrinted = nLinesPrinted + write( tostring( v ) )
 end
 nLinesPrinted = nLinesPrinted + write( "\n" )
 return nLinesPrinted
end
mayaman79 #30
Posted 08 March 2012 - 01:28 AM
A quick question:

Is there a way to decide how long he will broadcast?
Advert #31
Posted 08 March 2012 - 02:37 AM
A quick question:

Is there a way to decide how long he will broadcast?

The broadcast is instant; any computer that is using os.pullEvent() or rednet.recieve() at the time of the broadcast will receive the message. Computers using sleep() will not, however (unless they are also using the prior).
mayaman79 #32
Posted 08 March 2012 - 03:49 AM
Okey, thanks for that one :mellow:/>/>
pieiscool32 #33
Posted 10 March 2012 - 01:30 PM
Ok, so I'm having problems, i just wrote this up and i keep getting an error for "line 22" Server code = here. For anyone who cares, Client code = here. Note that i'm kinda new, well at least to rednet.
Espen #34
Posted 10 March 2012 - 02:38 PM
Hey, I took a quick look at that line and here's what I found:

It's not recieve, but receive. Also I think you mistyped and it should be message, not messgae.
Also, rednet.receive() takes a numerical parameter for its timeout.
That means this…
local id, message = rednet.receive(10)
… would make it wait for 10 seconds for any incoming messages.
Not passing any parameter like this…
local id, message = rednet.receive()
… would make it wait until a message arrives.

To get info on other rednet functions, you can type this: help rednet
pieiscool32 #35
Posted 10 March 2012 - 04:12 PM
ok, thanks, i wasn't looking for typos, whoops…

EDIT: i went to look at the client and i set up line 5 like this: "local 2, message = rednet.receive(10)" and now it says it needs a <Name>… what name?
3istee #36
Posted 10 March 2012 - 05:03 PM
I have written a code to detect modems or any other peripherals:


Sides = {"back","right","left","front","top","bottom"}
for i=1,#Sides do
if peripheral.isPresent(Sides[i]) then
  if peripheral.getType(Sides[i]) == "modem" then
   side = Sides[i]
  end
end
end

Then you could give out an error message, if there is no modem:


if side == nil then
  print("This computer has no modem.")
end
Espen #37
Posted 10 March 2012 - 06:25 PM
ok, thanks, i wasn't looking for typos, whoops…

EDIT: i went to look at the client and i set up line 5 like this: "local 2, message = rednet.receive(10)" and now it says it needs a <Name>… what name?
2 is not a variable.
rednet.receive() returns two values: the sender ID and the message.
If you write e.g. something like this…
local id, msg = rednet.receive()
… then id will contain the Id of the sender, because that is returned first and msg will contain the message, because that is returned second.
And it doesn't matter here what name id and msg are, you could just as well write:
local popcorn, fireworks = rednet.receive()
pieiscool32 #38
Posted 10 March 2012 - 06:44 PM
so then how can i receive messages from only one sender? and then have the program read said messages
Espen #39
Posted 10 March 2012 - 07:13 PM
You can't choose not to receive messages, but you can choose to ignore them if they don't come from a sender you want to listen to. :mellow:/>/>
That is, once you received the ID of the sender, you compare it to the ID (or list of IDs) you want to listen to.
E.g.:

local id, msg = rednet.receive()
if id == 5 then
  print( "Message from #"..id..": "..msg )
end
This will ignore messages from every ID except 5.
If, for example, sender #5 sent the message "Tomatoes are red.", then the code above would result in this output:
Message from #5: Tomatoes are red.
pieiscool32 #40
Posted 11 March 2012 - 06:49 PM
ok, when i send my client a message using this code

while true do
rednet.open("right")
msg = rednet.receive(10)
print(msg)
end

and any message that i send it looks like this:

>msg


7

("7" is the # of the comp i am sending it from)
what is wrong here, and i made more complicated code that does about the same, it doesn't read the message properly.
3istee #41
Posted 11 March 2012 - 06:56 PM
"rednet.receive"
has two Arguments.
The first is the ID of the sender, the second is the message.
In order to save the message you need to save both arguments, since the ID is the first argument and you want the second.
So you type:

id,msg = rednet.receive(10)

This should work.
MysticT #42
Posted 11 March 2012 - 06:57 PM
ok, when i send my client a message using this code

while true do
rednet.open("right")
msg = rednet.receive(10)
print(msg)
end

and any message that i send it looks like this:

>msg


7

("7" is the # of the comp i am sending it from)
what is wrong here, and i made more complicated code that does about the same, it doesn't read the message properly.

Like Espen said, rednet.receive() returns 2 values: the id of the sender and the message. You have to store them in variables, like this:

local id, msg = rednet.receive()
the first value that is returned it's the id, the second is the message. If you do:

local msg = rednet.receive()
the variable msg will contain the id of the sender, not the message, because it is the first value returned, it doesn't matter what name you give to the variable.
Espen #43
Posted 11 March 2012 - 07:01 PM
ok, when i send my client a message using this code
 while true do rednet.open("right") msg = rednet.receive(10) print(msg) end 
and any message that i send it looks like this: >msg 7 ("7" is the # of the comp i am sending it from) what is wrong here, and i made more complicated code that does about the same, it doesn't read the message properly.
The first value returned by rednet.receive() will be the senders ID. Only the second value will be the message!
So if you only assign one variable to be filled by the return values of rednet.receive(), then it will be the first return value that the variable will be set to.

Read post #37 again, carefully. :mellow:/>/>

EDIT: Wow, ninja'd 2 times.^^
Edited on 11 March 2012 - 06:01 PM
pieiscool32 #44
Posted 11 March 2012 - 07:14 PM
ok, but then how do i make it so a program reads the message but not the id of the compuer?
Liraal #45
Posted 11 March 2012 - 07:20 PM
_,message=rednet.receive()
pieiscool32 #46
Posted 11 March 2012 - 07:27 PM
_,message=rednet.receive()

are you sure…
Espen #47
Posted 11 March 2012 - 07:30 PM
ok, but then how do i make it so a program reads the message but not the id of the compuer?
You assign rednet.receive to two variables and just ignore the variable you don't need.
Like in the previous examples.


But maybe you're not getting how the assignment of multiple variables works?
If that's the case:

If a function x returns multiple values, then you can get them like this:
firstResult, secondResult, thirdResult = x()
Important to note here is that your variables are being filled with the return values of x() in the order you put them!
I.e. firstResult will contain the first return value, and so on.

Now, if you only need the second return value, but neither the first nor the last, nor any other, etc. then you can't do something like this:
secondResult = x()
Because then secondResult will receive the first return value of x().
You have to at least add one more variable, which you'll then just ignore:
firstResult, secondResult = x()

With ignored variables it is common practice to use an underscore as a name, like Liraal did above this post:
_, secondResult = x()
(You could stil use _ to access the first return value, if you wanted. It's just for easier recognition)
Edited on 11 March 2012 - 06:34 PM
pieiscool32 #48
Posted 11 March 2012 - 07:33 PM
ok, i just am new to coding, thanks, and sorry for me looking like an idiot, cuz i kinda am… (at least at code)
Espen #49
Posted 11 March 2012 - 07:35 PM
Well we all started with a clean slate. You can only get better. No shame in that.
6677 #50
Posted 14 March 2012 - 02:41 PM
"rednet.receive"
has two Arguments.
well, as of 1.31 it also has a 3rd argument which is the distance the message was recieved from.
jmcneely #51
Posted 14 March 2012 - 08:03 PM
Is there anyway to get the label of a computer using the received ID number?
ironsmith123 #52
Posted 14 March 2012 - 11:38 PM
Okay, so I get it now, but how would i send a command such as "tunnel 80"?
jmcneely #53
Posted 15 March 2012 - 02:07 AM
Okay, so I get it now, but how would i send a command such as "tunnel 80"?
While I wait for an answer to my question, I can try to help you ironsmith123. A trick I did, after the computer or turtle recieves the id and message it then compares the message to several built in keywords within the program. When the program finds a match it launches the program that the keywords is for. Here is a small example:

local id, cmd = rednet.receive(10)
if cmd == nil then
print("Time out.")
elseif cmd == "lumberjack" then
shell.run("lumberjack")
else
print("compy "..id..": "..cmd)
end
The first if statement is for when nothing is found with in the time limit stated. The elseif is what happens when the cmd variable matches the built in keyword, "lumberjack", which is a program I have within my turtle to cut down a tree. And, the last one is for when cmd doesn't match and just displays it like "compy 1: Hello."

I hope this helps a little, I am new to Lua and only know basic Java. I know you asked for "tunnel 80" but I'm not sure how to separate the message variable into two different variables so to be passed through shell.run(program, argument). When I found a way, I'll be sure to post the results here.
ironsmith123 #54
Posted 15 March 2012 - 04:59 AM
Is there anyway to get the label of a computer using the received ID number?
I believe to find the ID of the computer or turtle just type id and it gives you that id. Btw, I'd be happy to whitelist you on my cc server I have set up. The address is 24.237.251.57:25566
Please tell me ur mc ign so I can whitelist you of your interested. :D/>/>
6677 #55
Posted 15 March 2012 - 08:56 AM
Is there anyway to get the label of a computer using the received ID number?
I believe to find the ID of the computer or turtle just type id and it gives you that id. Btw, I'd be happy to whitelist you on my cc server I have set up. The address is 24.237.251.57:25566
Please tell me ur mc ign so I can whitelist you of your interested. :D/>/>
He wanted the ID of another computer.

The answer, you can't directly although you could keep a list locally of what id has what label and then do a local comparison. You could also send a message "GET_ID" to that computer and have it return its label to update your local list.
Espen #56
Posted 15 March 2012 - 11:48 AM
Is there anyway to get the label of a computer using the received ID number?
I believe to find the ID of the computer or turtle just type id and it gives you that id. Btw, I'd be happy to whitelist you on my cc server I have set up. The address is 24.237.251.57:25566
Please tell me ur mc ign so I can whitelist you of your interested. :D/>/>
He wanted the ID of another computer.

The answer, you can't directly although you could keep a list locally of what id has what label and then do a local comparison. You could also send a message "GET_ID" to that computer and have it return its label to update your local list.
In theory one could make seomthing like a DNS-Server for his/her world, where every computer can register itself with its label.
The DNS-Server maps the label to the computer ID it received the label from and other computers can then make name resolution queries.

The proof-of-cocept version wouldn't be terribly safe of course, since it need the DNS-Server to "believe" what it's being told by the computers.^^
Also, since it's not really "domains" but "labels", it might be better to call it LNS? Or even LS?
Well, whatever, it was just an idée fixe anyway. :)/>/>
ironsmith123 #57
Posted 15 March 2012 - 06:06 PM
So does anyone know how to send commands such as "tunnel 80" to a turtle over rednet?
Espen #58
Posted 15 March 2012 - 06:10 PM
So does anyone know how to send commands such as "tunnel 80" to a turtle over rednet?
There are a couple of threads about this. Use the forum search with "remote" and search in titles only. That should point you in the right direction.
Muud12 #59
Posted 15 March 2012 - 06:52 PM
Make this is impossible
Liraal #60
Posted 15 March 2012 - 06:56 PM
Make this is impossible
Logic please.
jmcneely #61
Posted 16 March 2012 - 04:13 AM
He wanted the ID of another computer.

The answer, you can't directly although you could keep a list locally of what id has what label and then do a local comparison. You could also send a message "GET_ID" to that computer and have it return its label to update your local list.
Thank you very much, that is exactly what I was looking for. I had a small solution before I read what you said, a similar solution to your first suggestion. But, with a lot of time and head aches, I finally got it to pick up the sending computer's label by making both computers do a few information transfers. So on the other receiving end it will look like "Master Computer: Blah blah" or if no label "Compy 0: blah blah". Thanks again 6677.

And to Ironsmith123, I was thinking about your problem and thought of something that should work. You could just send "excavate" and when the turtle receives that message it then sends the message "how much?" Then you send the number and it will know how much to excavate. I haven't tested it, just brainstorming.
SquareMan #62
Posted 25 March 2012 - 04:05 PM
Im pretty new to Computer Craft and lua programming in general, but for the tunnel 80 couldn't he do something like,


shell.run(program.." "..param)

where program is the program the turtle received instructions to run, and param is the parameters needed.
so at the pc's end the program could do something like


print ("what is the program?")
local program = io.read()
print("what is the parameter?")
local param = io.read()

then send that to the turtle, haven't tested it but figured it would work






I also have a problem however,
So i have written two programs, turtleSend.lua and pcReceive.lua, saved in CC's lua/rom/programs/computer and turtle, respectively
Heres the code,


turtleSend.lua


print("What side is your modem on?")
local side = io.read() --Find the side of the PC with the Modem
rednet.open(side)

term.write("Info to send:")
info = io.read() --Gather the info to send

print("What ID is your Turtle?")
local TurtID = io.read() --Find the ID of the receiving Turtle

TurtID = tonumber(TurtID)
rednet.send(TurtID, info) -- Send the info



pcReceive.lua


rednet.open("right")
message = "Blank"
id = 0
while message == "Blank" do --keep looking for info until received
     id, message = rednet.receive(10)
end
if message ~= "Blank" then
     print("Incoming Info From PC #",id)
     print("Info:")
     print(message)
end

I run pcReceive.lua from the turtle, then it waits for info, as it should

then i run turtleSend.lua from the pc,
it asks what side the modem is on
i type "right"

it asks what info i want to send
i type "Test"

it asks what is the turtles ID
i type 2 because thats what the turtle returned when i typed id in it

then i go to my turtle and it just says

Incoming Info From PC #
Info:


With blanks where the sent information is supposed to be, as if they are blank.
Casper7526 #63
Posted 25 March 2012 - 04:24 PM
while message == "Blank" do keep looking for info until received
id
, message = rednet.receive(10)
end


If you want to just continue waiting until a message is received try.

id, message = rednet.receive()

Pretty sure that will fix your issue and you dont need the while loop mess
SquareMan #64
Posted 25 March 2012 - 04:29 PM
Thanks so much, you fixed it!
qwerty6543 #65
Posted 01 April 2012 - 04:12 PM
I went in to lua and typed rednet.send(39, "Hello") to a computer that was listening with open modems but all it did was put the listening computer out of listening mode. I tried it like 10 time but no avail. help!
qwerty6543 #66
Posted 07 April 2012 - 12:35 AM
I went in to lua and typed rednet.send(39, "Hello") to a computer that was listening with open modems but all it did was put the listening computer out of listening mode. I tried it like 10 time but no avail. help!
Never Mind, i found out i did ot do the print(message) thing.

I went in to lua and typed rednet.send(39, "Hello") to a computer that was listening with open modems but all it did was put the listening computer out of listening mode. I tried it like 10 time but no avail. help!
Never Mind, i found out i did ot do the print(message) thing.
not not ot
strideynet #67
Posted 11 April 2012 - 07:38 AM
Espen have you seen project netblock is general discussion
If you,interested you can join it as you have alot of knolledge!
Espen #68
Posted 16 April 2012 - 11:20 AM
Espen have you seen project netblock is general discussion
If you,interested you can join it as you have alot of knolledge!
Hey strideynet, I appreciate your confidence in me, but I'm afraid I'm don't have much time at the moment.
The new semester has begun and uni work is keeping me quite busy. Part of which means I have to code in 2 different languages and the little time I have left to hobbies doesn't really encourage me to code even more with Lua, as I'm sure you can understand.^^
But as soon as I'm done with my exams I'll be back, guaranteed. And then I'm curious to see all the changes that'll have occurred here in the meantime.
So again, sorry, I'd really like to participate, but RL won't let me at the moment. I'll keep checking back every now and then though, to keep up with posts directed at me, just like I'm doing right now with your's, etc.
K, enough with me derailing this thread :)/>/> Take care and I'm sure you guys will make a nice netblock mod if you set your mind to it.
Cheers! :)/>/>
Lolgast #69
Posted 08 May 2012 - 08:34 AM
Yes, I'm new, this is in fact my first reply on this site ever, but I was wondering, is there a possibility to send and receive variables using the rednet? For example, I have computer #1 with variable a = 7, and I want to send a to computer #2. Nvm, already found it.
ToySoldier1992 #70
Posted 22 May 2012 - 09:39 AM
A system that mimics DNS, but for labeling PCs would be awesome. No more remembering IDs, just give PCs a name and let them broadcast it, simular to the ARP function. I will be playing around with this soon :P/>/>
Shaso777 #71
Posted 16 June 2012 - 07:44 AM
Just looking for some answers, What i am trying to do with my computer set up is:
1) Have a master computer send out commands to other computers such as shutdown or power redstone.
2) Have those receiving computers also run other programs such as a keycard/password system.

So far my attempts have failed, i did use Espen's event code to attempt to receive messages but so far it has yet to work. Can anyone help me with this?
Bossman201 #72
Posted 21 June 2012 - 11:10 PM
If you wanted to support a dynamic number of turtles without having to store all their id's you could always keep the rednet.broadcast(message/command) add encryption to the message beforehand. The turtle could read the first few values when they receive a command to decide if the message was encrypted for them. Just thinking outside the CPU- I mean box.
Elite #73
Posted 27 June 2012 - 07:46 PM
Is there any program that would allow me to broadcast/send from upto more than 50 blocks using a computer halfway? Say I want to broadcast something 100 blocks away. I place a computer 50 blocks away. This way its perfectly inbetween the receiving and sending side. Is there a program that could forward the message to the next computer?
MysticT #74
Posted 27 June 2012 - 07:55 PM
Is there any program that would allow me to broadcast/send from upto more than 50 blocks using a computer halfway? Say I want to broadcast something 100 blocks away. I place a computer 50 blocks away. This way its perfectly inbetween the receiving and sending side. Is there a program that could forward the message to the next computer?
Not the place to ask, but I think there's one in the program library, just search there.
diegodan1893 #75
Posted 11 July 2012 - 08:05 PM
I need help. I get this error in my computer2

rednet:350: string expected

Complete output:

iniciando
recibiendo
rednet:350: string expected

Here is my code:
Computer 1 (it isn't the complete code but it's the wireless part)

function compConex()
term.clear()
borde()
term.setCursorPos(3,17)
write("Intentando conectar con cliente...")
rednet.open("right")
rednet.broadcast("ping")
id, rUserName = rednet.receive(10)
term.setCursorPos(3,17)
term.clearLine()

if rUserName == nil then
  term.setCursorPos(3,17)
  term.clearLine()
  write ("No ha sido posible establecer una conexión")
  bRedNet = false
  sleep(4)
else
  write("Comprobando nombre de usuario...")
end

if rUserName ~= UserName then
  term.setCursorPos(3,17)
  term.clearLine()
  write ("Nombre de usuario incorrecto")
  bRedNet = false
  sleep(4)
elseif rUserName == UserName then
  term.setCursorPos(3,17)
  term.clearLine()
  write("Comprobando contraseña...")
  id, rPassword = rednet.receive(10)
  if rPassword == Password then
   term.setCursorPos(3,17)
   term.clearLine()
   write("Conectado correctamente")
   bRedNet = true
   --guardar id
   sleep(4)
  else
   bRedNet = false
   term.setCursorPos(3,17)
   term.clearLine()
   write ("Contraseña incorrecta")
   sleep(4)
  end
end
end
print ("user")
UserName = io.read()
print ("pass")
Password = io.read()
compConex()

Computer 2

UserName = "testname"
UserName = "testpass"
message = "blank"
while true do
print ("iniciando")
rednet.open("right")
id, message = rednet.receive()
print ("recibiendo")
if message == "ping" then
  rednet.send(id, UserName)
  sleep(2)
  rednet.send(id, Password)
end
end

Thanks.
MysticT #76
Posted 11 July 2012 - 09:43 PM
This is not the place to ask, you should make a post about this.
Anyway, the problem is that you define UserName twice, and never Password, so when you do rednet.send(id, Password), it's nil.
Change the second UserName = … to Password = …
diegodan1893 #77
Posted 12 July 2012 - 11:03 AM
Sorry for post it here.
Thanks so much, I do not know how I did not realize before.
Klausar #78
Posted 29 September 2012 - 09:49 AM
Maybe someone already wrote it, but how can you run a program on a turtle from a Computer?
raywave #79
Posted 13 January 2013 - 09:48 AM
my first program is a computer on the ground, sending stuff to a high altitude relay that will broadcast it to other computers and keep track of what the message is.
Appleeater #80
Posted 25 January 2013 - 05:56 AM
This is nice, how could I use this to send files and revive files?
Cranium #81
Posted 25 January 2013 - 08:57 AM
This is nice, how could I use this to send files and revive files?
You can read the file, then put it into a string, then send it over rednet. Somethign like this:

local readFile = fs.open("<filename>", "r")
local fileTab = {}
repeat
  table.insert(fileTab, readFile.readLine())
until readFile.readLine() == nil
readFile.close()

rednet.open("<side>")
rednet.send(<ID>, textutils.serialize(fileTab))
rednet.close()
That will send the file in a table, line by line.

rednet.open("<SIDE>")
local id, msg, dist = rednet.receive()
local contents = textutils.unserialize(msg)
local saveFile = fs.open("<FILENAME>", "w")
for i = 1, #contents do
  saveFile.writeLine(contents[i])
end
saveFile.close()
That should receive the file and save it.
Appleeater #82
Posted 25 January 2013 - 09:08 PM
This is nice, how could I use this to send files and revive files?
You can read the file, then put it into a string, then send it over rednet. Somethign like this:

local readFile = fs.open("<filename>", "r")
local fileTab = {}
repeat
  table.insert(fileTab, readFile.readLine())
until readFile.readLine() == nil
readFile.close()

rednet.open("<side>")
rednet.send(<ID>, textutils.serialize(fileTab))
rednet.close()
That will send the file in a table, line by line.

rednet.open("<SIDE>")
local id, msg, dist = rednet.receive()
local contents = textutils.unserialize(msg)
local saveFile = fs.open("<FILENAME>", "w")
for i = 1, #contents do
  saveFile.writeLine(contents[i])
end
saveFile.close()
That should receive the file and save it.

Thanks is there any way I can make it save as anything from the sending pc so I could make it save as whatever I want from the sending computer
UnicornForrest #83
Posted 09 February 2013 - 07:24 AM
Im trying to write a program to send and receive messages, but its not working.
Im trying to use local id = read() to save what number you type for the computer id youre sending to, but when i do
rednet.send("..id..","..msg..") it says the id needs to be a positive number. I know that this should replace id with the number, but it doesnt work.
Herû #84
Posted 09 February 2013 - 10:37 AM
Im trying to write a program to send and receive messages, but its not working.
Im trying to use local id = read() to save what number you type for the computer id youre sending to, but when i do
rednet.send("..id..","..msg..") it says the id needs to be a positive number. I know that this should replace id with the number, but it doesnt work.
If you use rednet.send("..id..","..msg..") and id is 3 and msg is "Hello world!", you will send the message "..msg.." To computerid "..id.." and not the message "Hello world!" To computerid 3 (remember how you shall define variables (" shall not be used))

Use rednet.send(id,msg) (you do not need .. If you do not shall have both plain text and variables together).
UnicornForrest #85
Posted 09 February 2013 - 12:07 PM
Im trying to write a program to send and receive messages, but its not working.
Im trying to use local id = read() to save what number you type for the computer id youre sending to, but when i do
rednet.send("..id..","..msg..") it says the id needs to be a positive number. I know that this should replace id with the number, but it doesnt work.
If you use rednet.send("..id..","..msg..") and id is 3 and msg is "Hello world!", you will send the message "..msg.." To computerid "..id.." and not the message "Hello world!" To computerid 3 (remember how you shall define variables (" shall not be used))

Use rednet.send(id,msg) (you do not need .. If you do not shall have both plain text and variables together).
It still doesnt work. It keeps saying rednet:347: positive number expected.



os.pullEvent = os.pullEventRaw
term.clear()
term.setCursorPos(1,1)
rednet.open("top")
print("Broadcast or personal message?")
input = read()
if input == "broadcast" then
 term.clear()
 term.setCursorPos(1,1)
 write("Message:")
 local msg = read()
 rednet.broadcast("'..msg..'")
 print("Sent")
 sleep(2)
 os.reboot()
elseif input == "personal" then
 term.clear()
 term.setCursorPos(1,1)
 write("To:")
 local id = read()
 write("Message:")
 local msg = read()
 rednet.send(id,msg)
 print("Sent")
 sleep(2)
 os.reboot()
end
Edited on 09 February 2013 - 11:08 AM
MudkipTheEpic #86
Posted 09 February 2013 - 03:31 PM
–snip–
You were not making the ID a number, so here is the correct code.
Spoiler

local oldPull = os.pullEvent
os.pullEvent = os.pullEventRaw
term.clear()
term.setCursorPos(1,1)
rednet.open("top")
print("Broadcast or personal message?")
local input = read()
if input == "broadcast" then
term.clear()
term.setCursorPos(1,1)
write("Message:")
local msg = read()
rednet.broadcast(msg)
print("Sent")
sleep(2)
os.reboot()
elseif input == "personal" then
while true do
term.clear()
term.setCursorPos(1,1)
write("To:")
local id = tonumber(read())
if id ~= nil then break end
print("ID must be a number.")
sleep(1)
end
write("Message:")
local msg = read()
rednet.send(id,msg)
print("Sent")
sleep(2)
os.reboot()
end
UnicornForrest #87
Posted 09 February 2013 - 04:08 PM
–snip–
You were not making the ID a number, so here is the correct code.
Spoiler

local oldPull = os.pullEvent
os.pullEvent = os.pullEventRaw
term.clear()
term.setCursorPos(1,1)
rednet.open("top")
print("Broadcast or personal message?")
local input = read()
if input == "broadcast" then
term.clear()
term.setCursorPos(1,1)
write("Message:")
local msg = read()
rednet.broadcast(msg)
print("Sent")
sleep(2)
os.reboot()
elseif input == "personal" then
while true do
term.clear()
term.setCursorPos(1,1)
write("To:")
local id = tonumber(read())
if id ~= nil then break end
print("ID must be a number.")
sleep(1)
end
write("Message:")
local msg = read()
rednet.send(id,msg)
print("Sent")
sleep(2)
os.reboot()
end
Thanks. That actually works. Now I need to make them able to receive.
tommas #88
Posted 13 February 2013 - 09:02 AM
Great Thanks for the help i made a password locked door and every password wrong or correct is now send to my computer!
hoanganhlam #89
Posted 14 February 2013 - 10:38 PM
aswesome
Doyle3694 #90
Posted 14 February 2013 - 11:39 PM
Casper/ anyone who can edit, maybe add a note on top of the tutorial that this is not how modems work anymore?
BaconHawk101 #91
Posted 08 March 2013 - 02:44 PM
Sweet thanks man!
Dlcruz129 #92
Posted 08 March 2013 - 06:10 PM
Casper/ anyone who can edit, maybe add a note on top of the tutorial that this is not how modems work anymore?

Casper hasn't been on in ages. Tbh, I've never seen him post, besides forum guidelines and whatnot.
spysean1499 #93
Posted 16 March 2013 - 09:24 PM
dose anayone have a ftb server (for computercraft i am horrible a installing mods)with a WORKING e-mail system p.s how do i get a email system running?
thix
:)/> :> :X :D/>