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

Trouble with rednet? Check this out!

Started by Engineer, 18 January 2013 - 11:36 PM
Engineer #1
Posted 19 January 2013 - 12:36 AM
Hello,

Welcome to my rednet program. If you are bad with rednet in the lua interpreter, than you can use my program via shell.run("")
This is explained further in this topic.

This automatically turns on your rednet and sends it to your specified computer. If you dont got an ID, then it will broadcast!

Here is the code for it:


local tArgs = {...}

for k, v in pairs(rs.getSides()) do
  rednet.open(v)
end
local id = tonumber(tArgs[#tArgs])
tArgs[#tArgs] = nil

local msg = table.concat(tArgs," ")

if tArgs[1] == nil then
		print("Usage:\nRednet <message> <optional: id>")
elseif id ~= nil then
		rednet.send(id, msg)
print("Sent '"..msg.."' to computer: "..id)
elseif id == nil then  
tArgs[#tArgs] = nil
		rednet.broadcast(msg)
		print("Broadcasted: '"..msg.."'")
tArgs[#tArgs] = nil
end

or

pastebin get kk8aezHG program

"Program" can be changed into anything

Type in your computer: program <message> <optional ID>

If you want this to use in your lua interpreter, use:

shell.run("program <message> <optional ID>")

It's that easy! :D/>

Enjoy

(Please leave me feedback)

Changelog:
Spoiler- Changed topic name etc.
- Changed opening modems
Edited on 30 January 2013 - 02:50 AM
3ydney #2
Posted 19 January 2013 - 01:19 AM
Looks great but little bit dodgy …. tArgs..
Sammich Lord #3
Posted 19 January 2013 - 01:21 AM
You can open all modem sides by doing this:

for k,v in pairs(rs.getSides()) do
  rednet.open(v)
end
theoriginalbit #4
Posted 19 January 2013 - 01:22 AM
Looks great but little bit dodgy …. tArgs..
What are you on about… there is nothing 'dodgy' about tArgs… its a variable name, and in this case it stores the arguments supplied when the program is run… it is a table too, to the identifier 'tArgs' is fine…
remiX #5
Posted 19 January 2013 - 01:37 AM
I'd suggest putting the ID before the message so no tArgs[#tArgs] = nil has to be done? :P/>
Engineer #6
Posted 19 January 2013 - 02:03 AM
You can open all modem sides by doing this:

for k,v in pairs(rs.getSides()) do
  rednet.open(v)
end
Thank you very much, I implemented this now.

I'd suggest putting the ID before the message so no tArgs[#tArgs] = nil has to be done? :P/>

Well.. it works this way also right?:P/>

Still thank you for the feedback
Zudo #7
Posted 24 January 2013 - 07:10 AM

local tArgs = {...}

for k, v in pairs(rs.getSides()) do
  rednet.open(v)
end
local id = tonumber(tArgs[#tArgs])
tArgs[#tArgs] = nil

local msg = table.concat(tArgs," ")

if tArgs[1] == nil then
		print("Usage:\nRednet [message] [optional: id]")
elseif id ~= nil then
		rednet.send(id, msg)
print("Sended '"..msg.."' to computer: "..id)
SENDED??? :P/>
Engineer #8
Posted 24 January 2013 - 10:18 PM

local tArgs = {...}

for k, v in pairs(rs.getSides()) do
  rednet.open(v)
end
local id = tonumber(tArgs[#tArgs])
tArgs[#tArgs] = nil

local msg = table.concat(tArgs," ")

if tArgs[1] == nil then
		print("Usage:\nRednet [message] [optional: id]")
elseif id ~= nil then
		rednet.send(id, msg)
print("Sended '"..msg.."' to computer: "..id)
SENDED??? :P/>

Thanks for noticing, changed it to sent. Gotta love spelling errors xD
True #9
Posted 26 January 2013 - 11:52 PM
Just put this on Pastebin so it's much easier to install and saves you 5 mins instead of typing it all.

Type this into an advanced (gold) computer:

pastebin get Jm1RtD03 redmsg
Obviously you can change the "redmsg" to whatever you want the file to be called.
Mikeemoo #10
Posted 26 January 2013 - 11:55 PM
Is this really what passes for 'programs' these days?
Engineer #11
Posted 27 January 2013 - 02:01 AM
Is this really what passes for 'programs' these days?

Why so sad?
Engineer #12
Posted 27 January 2013 - 02:03 AM
Just put this on Pastebin so it's much easier to install and saves you 5 mins instead of typing it all.

Type this into an advanced (gold) computer:

pastebin get Jm1RtD03 redmsg
Obviously you can change the "redmsg" to whatever you want the file to be called.

You can get it via pastebin right now. Thank you