Advertisement
XDemonic

ComputerCraft - ChestChange_Master

Mar 31st, 2014
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.11 KB | None | 0 0
  1.         local mon = peripheral.wrap("top")
  2.         local wmod = peripheral.wrap("bottom")
  3.        
  4.         wmod.open(1)
  5.         wmod.open(2)
  6.         wmod.open(3)
  7.         wmod.open(4)
  8.         mon.clear()
  9.         mon.setTextScale(0.8)
  10.         mon.setCursorPos(1,1)
  11.        
  12. function StartUp()
  13.     while true do
  14.         local event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
  15.         local words = split(message,"|SPLIT|")
  16.         term.redirect(mon)
  17.         if words[1] == "ADDED" then
  18.         term.setTextColour(colors.green)
  19.             print("ADDED: "..words[3].. " ["..words[2].."]")
  20.             else
  21.         term.setTextColour(colors.red)
  22.             print("REMOVED: "..words[3].. " ["..words[2].."]")
  23.         end
  24.         term.restore()
  25.     end
  26. end
  27.  
  28. function split( str, regex )
  29.   local t = { }
  30.   local fpat = "(.-)"..regex
  31.   local last_end = 1
  32.   local s, e, cap = str:find(fpat, 1)
  33.   while s do
  34.         if s ~= 1 or cap ~= "" then
  35.           table.insert(t,cap)
  36.         end
  37.         last_end = e+1
  38.         s, e, cap = str:find(fpat, last_end)
  39.   end
  40.   if last_end <= #str then
  41.         cap = str:sub(last_end)
  42.         table.insert(t, cap)
  43.   end
  44.   return t
  45. end
  46.  
  47.  
  48. StartUp()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement