Advertisement
chopstyix

Untitled

Jan 7th, 2014
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. t = {
  2. {text="Enable Weapons",x=1,y=1,txtCol=color.white,bgCol=colors.green},
  3. {text="Disable Weapons",x=1,y=2,txtCol=color.white,bgCol=colors.green},
  4. }
  5.  
  6. mon = peripheral.wrap("right") -- Where is the Adv. Monitor located?
  7.  
  8. function writeButtons(_table)
  9. for i,v in pairs(_table) do
  10. term.setCursorPos(v.x,v.y)
  11. term.setTextColor(v.txtCol)
  12. term.setBackgroundColor(v.bgCol)
  13. write(v.text)
  14. end
  15. end
  16.  
  17. function isValidClick(_table,mx,my)
  18. for i,v in pairs(_table do
  19. if mx >=v.x and mx<= (v.x + #v.text) and my == v.y then
  20. return true, v.text
  21. end
  22. end
  23. return false, nil
  24. end
  25.  
  26. writeButtons(t)
  27.  
  28. while true do
  29. _, but, x,y, = os.pullEvent("monitor_touch")
  30. bClick, option = isValidClick(t,x,y)
  31. if bClick then
  32. if option == "Enable Weapons" then
  33. print("Weapons enabled!")
  34. elseif option == "Disable Weapons" then
  35. print ("Weapons disabled!")
  36. end
  37. end
  38. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement