Advertisement
Guest User

test

a guest
Aug 1st, 2014
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.18 KB | None | 0 0
  1. portals = {}
  2.  
  3. dial = peripheral.wrap("right")
  4. monitor = peripheral.wrap("left")
  5. sign = peripheral.wrap("top")
  6. conwrap = sign.getLine(4)
  7. controller = peripheral.wrap("ep_controller_"..conwrap)
  8. ident = controller.getUniqueIdentifier()
  9. portalname = sign.getLine(1).." - "..sign.getLine(2)
  10. portalActive = false
  11. locationCount = 0
  12. rednet.open("back")
  13.  
  14. function update()
  15.   rednet.broadcast("p,"..conwrap..ident..","..portalname)
  16.   id,message = rednet.receive(2)
  17.   if not message == nil then
  18.   arr = { message }
  19.   if #arr == 3 then
  20.      portals[#portals + 1] = { arr[2], arr[3] }
  21.   end
  22.   end
  23.   portalActive = controller.isPortalActive()
  24.   locationCount = #portals
  25. end
  26.  
  27. function drawScreen()
  28. i = 1
  29. if controller.isPortalActive() == false then
  30.  
  31. --mon2.clear()
  32. end
  33. --   monitor.setBackgroundColor(colors.green)
  34. --    monitor.clear()
  35.  --   monW, monH = monitor.getSize()
  36.   --  monitor.setCursorPos(monW / 2 - string.len("Terminate") / 2, monH / 2)
  37.  --   monitor.write("Terminate")
  38. --    mon2.setBackgroundColor(colors.red)
  39. --  mon2.clear()
  40.       monitor.setBackgroundColor(colors.black)  
  41.     monitor.clear()
  42.  
  43.          for index,values in pairs(portals) do
  44.           name = values[1]
  45.           monitor.setCursorPos(1, i)
  46.      
  47.         if (i % 2 == 0) then
  48.           monitor.setBackgroundColor(colors.gray)
  49.         else
  50.           monitor.setBackgroundColor(colors.lightGray)
  51.         end
  52.    
  53.            monW, monH = monitor.getSize()
  54.      
  55.         monitor.write(name)      
  56.         k = string.len(name)
  57.      
  58.         while (k < monW) do
  59.           monitor.write(" ")
  60.           k = k + 1
  61.         end
  62.  i = i + 1      
  63.       end
  64.    
  65.    
  66.   end
  67.  
  68.  
  69. function handleInput()
  70.   event, side, posX, posY = os.pullEvent("monitor_touch")
  71.  
  72.   if portalActive then
  73.     dial.terminate()
  74.   else
  75. if posY <= #portals then  
  76. --mon2.setCursorPos(1,1)
  77.               -- if unexpected_condition then error() end
  78.      local ok,error = pcall( dial.dial, portals[posY][2])
  79.    if not ok then
  80.   -- //mon2.write("Whoops - Try Again")
  81.    else
  82. --  // mon2.write(portals[posY][1])
  83.    end
  84.  
  85.   end
  86. end
  87. end
  88. while true do
  89.  
  90.    update()
  91.   drawScreen()
  92.   handleInput()
  93.   os.sleep(1)
  94.  
  95. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement