Alyssa

Modem API

Jul 29th, 2013
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.53 KB | None | 0 0
  1. function receive()
  2.  marg={os.pullEvent()}
  3.  if marg[1] == "modem_message" then
  4.   return true
  5.  else
  6.   return false
  7.  end
  8. end
  9.  
  10. function getside()
  11.  return marg[2]
  12. end
  13.  
  14. function getall()
  15.  return marg
  16. end
  17.  
  18. function getfromchan()
  19.  return marg[3]
  20. end
  21.  
  22. function getreplychan()
  23.  return marg[4]
  24. end
  25.  
  26. function getmsg()
  27.  return marg[5]
  28. end
  29.  
  30. function getdistance()
  31.  return marg[6]
  32. end
  33.  
  34. function open(side, chan)
  35.  if peripheral.isPresent(side) and peripheral.getType(side) == "modem" then
  36.   local modems = peripheral.wrap(side)
  37.   modems.open(chan)
  38.  else
  39.   print("Modem not present on "..side.."")
  40.  end
  41. end
  42.  
  43. function transmit(chan, replychan, msgtosend)
  44.  local newchan = tonumber(chan)
  45.  local newreplychan = tonumber(replychan)
  46.  sidepresent = nil
  47.  for c = 1, 7 do
  48.   if c == 1 then
  49.    sidetocheck = "right"
  50.   end
  51.   if c == 2 then
  52.    sidetocheck = "left"
  53.   end
  54.   if c == 3 then
  55.    sidetocheck = "back"
  56.   end
  57.   if c == 4 then
  58.    sidetocheck = "front"
  59.   end
  60.   if c == 5 then
  61.    sidetocheck = "top"
  62.   end
  63.   if c == 6 then
  64.    sidetocheck = "bottom"
  65.   end
  66.   if c == 7 then
  67.    if sidepresent == nil then
  68.     return false
  69.    end
  70.   else
  71.    if peripheral.isPresent(sidetocheck) and peripheral.getType(sidetocheck) == "modem" then
  72.     sidepresent = sidetocheck
  73.    end
  74.   end
  75.  end
  76.  local modems = peripheral.wrap(sidepresent)
  77.  modems.transmit(newchan, newreplychan, msgtosend)
  78. end
  79.  
  80. function seperate()
  81.  toreturn = {}
  82.   for a, b in string.gmatch(marg[5], "(%S+)") do
  83.    toreturn[a] = b
  84.   end
  85.  return toreturn
  86. end
Advertisement
Add Comment
Please, Sign In to add comment