Advertisement
Guest User

browser

a guest
Mar 3rd, 2015
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.77 KB | None | 0 0
  1. local back = colors.blue
  2. local button = colors.green
  3. local text = colors.black
  4. function draw()
  5.   term.setTextColor(text)
  6.   term.setBackgroundColor(back)
  7.   term.clear()
  8.   for i,v in pairs(buttons) do
  9.     term.setBackgroundColor(button)
  10.     term.setCursorPos(v[2],v[3])
  11.     write(v[1])
  12.   end
  13.   term.setBackgroundColor(back)
  14. end
  15. buttons = {}
  16. buttons[1] = {} --create a new button
  17. buttons[1][1] = "Test"-- button title
  18. buttons[1][2] = 3 --button x
  19. buttons[1][3] =10 --buttons y
  20. buttons[1][4] = function() --function if the button is pressed
  21.   print("Button 1 pressed")
  22. end
  23. draw()
  24. while true do
  25.   local evt,b,x,y = os.pullEvent("mouse_click")
  26.   for i,v in pairs(buttons) do
  27.     if v[2] <= x and v[2] + #v[1] >= x and v[3] == y then
  28.       v[4]()
  29.     end
  30.   end
  31. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement