Guest User

main

a guest
Aug 18th, 2016
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.80 KB | None | 0 0
  1. local mon = peripheral.wrap("top")
  2.  
  3. local t = {text = "help", ymin = 1, ymax = 6, xmin = 8, xmax = 30, txCol = colours.black, bgCol = colours.lime}
  4.  
  5. function writeButton(_table)
  6.   for i,v in pairs(_table) do
  7.     ytxt = (v.ymin + v.ymax) / 2
  8.     xtxt = (v.xmin + v.xmax) / 2 - string.len(v.text)
  9.     mon.setCursorPos(xtxt, ytxt)
  10.     mon.write(v.text)
  11.     mon.setTextColour(v.txCol)
  12.     mon.setBackgroundColour(v.bgCol)
  13.   end
  14. end
  15.  
  16. function isValidClick(_table, mx, my)
  17.   for i, v in pairs(_table) do
  18.     if mx <= v.xmax and mx >= v.xmin and my <= v.ymax and my >= v.ymin then
  19.       f = v.text
  20.     end
  21.   return false
  22.   end
  23. end
  24.  
  25. writeButton(t)
  26.  
  27. while true do
  28.   event, but, x, y = os.pullEvent("monitorTouch")
  29.   isValidClick(t, x, y)
  30.   if f == help then
  31.     mon.print('hellp')
  32.   end
  33. end
Add Comment
Please, Sign In to add comment