Advertisement
Guest User

portal

a guest
Sep 21st, 2014
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.13 KB | None | 0 0
  1. os.loadAPI("/menu")
  2.  
  3. local protocol = "utility"
  4.  
  5. rednet.open("back")
  6.  
  7. local server = rednet.lookup(protocol, "portalControl")
  8.  
  9. function open(book)
  10. --  term.setBackgroundColor(colors.black)
  11. --  term.setTextColor(colors.white)
  12. --  term.clear()
  13. --  print(book)
  14.   rednet.send(server, tostring(book), protocol)
  15.   --local id, response = rednet.receive(protocol)
  16. end
  17.  
  18. function resetTerm()
  19.   term.setBackgroundColor(colors.black)
  20.   term.setTextColor(colors.white)
  21.   term.setCursorPos(1, 1)
  22.   term.clear()
  23. end
  24.  
  25. rednet.send(server, "list", protocol)
  26. local id, response = rednet.receive(protocol)
  27.  
  28. for i, v in pairs(response) do
  29.   menu.addItem(tostring(v), open, i)
  30. end
  31.  
  32. menu.draw()
  33.  
  34. while true do
  35.   local event, key = os.pullEvent("key")
  36.  
  37.   if key == 28 then
  38.     term.setCursorPos(1,1)
  39.     term.setBackgroundColor(colors.black)
  40.     term.setTextColor(colors.white)
  41.     term.clear()
  42.    
  43.     local item = menu.getSelectedItem()
  44.     item["callback"](item["arg"])
  45.  
  46.     break
  47.   elseif key == 200 then
  48.     menu.up()
  49.   elseif key == 208 then
  50.     menu.down()
  51.   elseif key == 20 then
  52.     resetTerm()
  53.     break
  54.   end
  55. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement