Advertisement
rhn

Elevator Touchscreen

rhn
Aug 3rd, 2014
492
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.79 KB | None | 0 0
  1. --Load floor location from disk
  2. local FloorFile = fs.open("disk/floor", "r")
  3.  
  4.  
  5. if FloorFile then
  6.     ThisFloor = tonumber(FloorFile.readLine())
  7.     print("This floor: "..ThisFloor)
  8.     FloorFile.close()
  9. else
  10.     print("No Floor File/disk found")
  11.     return
  12. end
  13.  
  14. os.setComputerLabel("Elevator"..ThisFloor)
  15.  
  16. local buttontext = {}
  17. buttontext[1]="Floor 1         "
  18. buttontext[2]="Floor 2         "
  19. buttontext[3]="Floor 3         "
  20. buttontext[4]="Floor 4         "
  21. buttontext[5]="Floor 5         "
  22. buttontext[6]="Floor 6         "
  23. buttontext[7]="Floor 7         "
  24. buttontext[8]="Floor 8         "
  25. buttontext[9]="Floor 9         "
  26.  
  27. local buttoncolours={}
  28. for k=1, #buttontext do
  29.     buttoncolours[k]=8192 --8192=green
  30. end
  31. buttoncolours[ThisFloor]=32 --32=lime
  32.  
  33. mouseWidth = 0
  34. mouseHeight = 0
  35.  
  36. monitor = peripheral.wrap("bottom")
  37.  
  38. monitor.clear()
  39. monitor.setCursorPos(1,1)
  40. w,h=monitor.getSize()
  41. print(w)
  42. print(h)
  43.  
  44. --Draw buttons
  45. for k=1, #buttontext do
  46.  
  47.     monitor.setBackgroundColour((buttoncolours[k]))
  48.     monitor.setCursorPos(2,k*2)
  49.     monitor.write(buttontext[k])
  50.     monitor.setBackgroundColour((colours.black))
  51. end --for
  52.  
  53.  
  54. function checkClickPosition()
  55.     for k=1, #buttontext do
  56.         if mouseWidth > 1 and mouseWidth < 18 and mouseHeight == k*2 and k~=ThisFloor then
  57.             redstone.setOutput("top", true)
  58.             sleep(1)
  59.             redstone.setAnalogOutput("back", k)
  60.             sleep(2)
  61.             redstone.setOutput("top", false)
  62.             redstone.setAnalogOutput("back", 0)
  63.         end
  64.     end
  65. end
  66.  
  67.  
  68. repeat
  69.         event,p1,p2,p3 = os.pullEvent()
  70.                 if event=="monitor_touch" then
  71.                         mouseWidth = p2 -- sets mouseWidth
  72.                         mouseHeight = p3 -- and mouseHeight
  73.                         checkClickPosition() -- this runs our function
  74.                 end
  75. until event=="char" and p1==("x")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement