Posted 05 August 2013 - 01:41 PM
I was tired of having to do modem = peripheral.wrap("right") and, I wanted to have something similar, but better
than regular rednet so I created this!
Functions:
receive, returns true if it receives a message, false if not.
getall, returns a table with all the info.
getside, returns which modem picked up the message.
getfromchan, return the channel the message was sent on.
getreplychan, returns the channel the sender wants you to reply on.
getmsg, returns the message that was sent.
getdistance, returns the distance of the sender.
open, needs 2 variables/strings, first for which side, second for the channel to open.
transmit, needs 3 strings/variables, first for the channel to send on, second for the channel you want the reply on, third for the message.
And, my favorite,
separate, returns a table of all of the words (separated by a space) in the message from receive, Tested, Currently DOES NOT WORK
To install just type(In Computer craft with http enabled) pastebin get vzw5KLjj modem
Code: (If you don't want to have to go to the pastebin address) –>Outdated<–
Some example programs:
Simple receiving program: pastebin.com/AdGhqAR3
than regular rednet so I created this!
Functions:
receive, returns true if it receives a message, false if not.
getall, returns a table with all the info.
getside, returns which modem picked up the message.
getfromchan, return the channel the message was sent on.
getreplychan, returns the channel the sender wants you to reply on.
getmsg, returns the message that was sent.
getdistance, returns the distance of the sender.
open, needs 2 variables/strings, first for which side, second for the channel to open.
transmit, needs 3 strings/variables, first for the channel to send on, second for the channel you want the reply on, third for the message.
And, my favorite,
separate, returns a table of all of the words (separated by a space) in the message from receive, Tested, Currently DOES NOT WORK
To install just type(In Computer craft with http enabled) pastebin get vzw5KLjj modem
Code: (If you don't want to have to go to the pastebin address) –>Outdated<–
Spoiler
function receive()
marg={os.pullEvent()}
if marg[1] == "modem_message" then
return true
else
return false
end
end
function getside()
return marg[2]
end
function getall()
return marg
end
function getfromchan()
return marg[3]
end
function getreplychan()
return marg[4]
end
function getmsg()
return marg[5]
end
function getdistance()
return marg[6]
end
function open(side, chan)
if peripheral.isPresent(side) and peripheral.getType(side) == "modem" then
local modems = peripheral.wrap(side)
modems.open(chan)
else
print("Modem not present on "..side.."")
end
end
function transmit(chan, replychan, msgtosend)
local newchan = tonumber(chan)
local newreplychan = tonumber(replychan)
sidepresent = nil
for c = 1, 7 do
if c == 1 then
sidetocheck = "right"
end
if c == 2 then
sidetocheck = "left"
end
if c == 3 then
sidetocheck = "back"
end
if c == 4 then
sidetocheck = "front"
end
if c == 5 then
sidetocheck = "top"
end
if c == 6 then
sidetocheck = "bottom"
end
if c == 7 then
if sidepresent == nil then
return false
end
else
if peripheral.isPresent(sidetocheck) and peripheral.getType(sidetocheck) == "modem" then
sidepresent = sidetocheck
end
end
end
local modems = peripheral.wrap(sidepresent)
modems.transmit(newchan, newreplychan, msgtosend)
end
function seperate()
toreturn = {}
for a, b in string.gmatch(marg[5], "(%S+)")
toreturn[a] = b
end
end
Some example programs:
Simple receiving program: pastebin.com/AdGhqAR3