Advertisement
Guest User

touch

a guest
Jun 29th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.48 KB | None | 0 0
  1. local screen = "top";
  2. local stargate = "stargate_1";
  3. local address = {
  4.     { name = "          Andrelec           ", adrs = "NKA5-KKC-XS", color = colors.red},
  5.     { name = "           Wetixx            ", adrs = "FLR4-82S-XS", color = colors.cyan},
  6.     { name = "            Deep             ", adrs = "9992-HVO-8S", color = colors.lime},
  7.     { name = "          Overworld          ", adrs = "US7I-59S-SA", color = colors.purple},
  8. };
  9. nbitem = #address;
  10. print("init with "..nbitem.." address");
  11. mouseWidth = 0;
  12. mouseHeight = 0;
  13. hp = 0;
  14. print("monitor wrap "..screen)
  15. monitor = peripheral.wrap(screen);
  16. w,h=monitor.getSize();
  17. print(w)
  18. print(h)
  19. monitor.setBackgroundColor(colors.black);
  20. monitor.clear();
  21. hp = hp +1;
  22. monitor.setCursorPos(1,hp)
  23. monitor.write("            Close            ");
  24. for key,value in pairs( address ) do
  25.     hp = hp +1;
  26.     monitor.setCursorPos(1,hp)
  27.     monitor.setBackgroundColor(value.color);
  28.     monitor.write(tostring(value.name));
  29. end
  30.  
  31. print("portal wrap "..stargate);
  32. local ppor = peripheral.wrap(stargate);
  33.  
  34.  
  35. function checkClickPosition()
  36.   if mouseHeight == 1 then
  37.     ppor.disconnect();
  38.   elseif mouseHeight ~= 1 and mouseHeight < nbitem then
  39.   print(mouseHeight);
  40.   print(address[mouseHeight - 1].adrs);
  41.     ppor.dial(address[mouseHeight - 1].adrs);
  42.   end
  43. end
  44.    
  45. repeat
  46.   event,p1,p2,p3 = os.pullEvent()
  47.    if event=="monitor_touch" then
  48.      mouseWidth = p2
  49.      mouseHeight = p3
  50.      checkClickPosition()
  51.    end
  52. until event=="char" and p1==("x")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement