tuogex

cc router

Nov 3rd, 2013
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.83 KB | None | 0 0
  1. local ins = "left"
  2. local out = "bottom"
  3. rednet.open(ins)
  4. rednet.open(out)
  5. -- data coming in formatted as "toId#data"
  6. while (true) do
  7.     local e, side, chan, repl, msg, dis = os.pullEventRaw("modem_message")
  8.     if (side == ins) then
  9.         local data = string.sub(msg, string.find(msg, "#") + 1)
  10.         local destId = string.sub(msg, 0, string.find(msg, "#") - 1)
  11.         print("routing " .. data .. " from " .. chan .. " to " .. destId)
  12.         peripheral.call(out, "transmit", tonumber(destId), repl, data)
  13.     end
  14.     if (side == out) then
  15.         local data = string.sub(msg, string.find(msg, "#") + 1)
  16.         local destId = string.sub(msg, 0, string.find(msg, "#") - 1)
  17.         print("routing " .. data .. " from " .. chan .. " to " .. destId)
  18.         peripheral.call(ins, "transmit", tonumber(destId), repl, data)
  19.     end
  20. end
Advertisement
Add Comment
Please, Sign In to add comment