Advertisement
Guest User

todoServer

a guest
Jul 19th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.03 KB | None | 0 0
  1. mon = peripheral.wrap("left")
  2. modem = peripheral.wrap("right")
  3. modem.open(1)
  4. term.redirect(mon)
  5. todo = {}
  6.  
  7. function split(str, pattern)
  8.   local out = {}
  9.   local start = 1
  10.   local splitS, splitE = string.find(str, pattern, start)
  11.  
  12.   while splitS do
  13.     table.insert(out, string.sub(str, start, splitS-1))
  14.     start = splitE+1
  15.     splitS, splitE = string.find(str, pattern, start)
  16.   end
  17.  
  18.   table.insert(out, string.sub(str, start))
  19.   return out
  20. end
  21.  
  22. while true do
  23.   --update screen loop
  24.   term.clear()
  25.   term.setCursorPos(1,1)
  26.   if todo then
  27.     for i, item in pairs(todo) do
  28.       print(item)
  29.     end
  30.   end
  31.   --getting messages from pocket computers
  32.   event, mS, sC, rC, message, sD = os.pullEvent("modem_message")
  33.   print("stall")
  34.   args = split(message, " ")
  35.   if args[1] == "add" then table.insert(todo, table.concat(args, " ", 2))
  36.   elseif args[1] == "remove" then
  37.     for i, item in pairs(todo) do
  38.       if item == table.concat(args, " ", 2) then table.remove(todo, i) break end
  39.   end
  40. end
  41. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement