Advertisement
Derek1017

Button

Apr 5th, 2015
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.44 KB | None | 0 0
  1. --Loads the API, straightforward
  2. os.loadAPI("touchpoint")
  3. --establish two "pages" of buttons
  4. local page1 = touchpoint.new("top")
  5. local page2 = touchpoint.new("top")
  6. --one variable to put each page into in order to simplify switching
  7. local t
  8.  
  9. --Two redstone testing functions
  10. --add toggling where it makes sense
  11. function rsRight()
  12.     page1:toggleButton("Activate Right")
  13.     rs.setOutput("right", not rs.getOutput("right"))
  14. end
  15.  
  16. function rsLeft()
  17.     page1:toggleButton("Activate Left")
  18.     rs.setOutput("left", not rs.getOutput("left"))
  19. end
  20.  
  21. --Redstone, switch out
  22. function redMenu()
  23.     t = page2
  24. end
  25.  
  26. ---Main Menu
  27. function mainTable()
  28.     t = page1
  29. end
  30.  
  31. --set up two pages
  32. do
  33.     page1:add("Redstone", redMenu, 5, 2, 20, 6)
  34.     page1:add("Turtle",function() turtleMenu() end, 25, 2, 40, 6)
  35.    
  36.     page2:add("Activate Left", rsLeft, 5, 12, 20, 16)
  37.     page2:add("Activate Right", rsRight, 25, 12, 40, 16)
  38.     page2:add("Back",mainTable, 15, 18, 25, 22)
  39. end
  40.  
  41. --Starts with the main Table, then checks for buttons clicked, toggles them, and runs the program it has with my modified t:run2()
  42. mainTable()
  43. while true do
  44.     t:draw()
  45.     -- local event, p1, p2, p3 = os.pullEvent() ---monitor_touch, side, xpos, ypos
  46.     local event, p1 = t:handleEvents(os.pullEvent())   ---button_click, name
  47.     if event == "button_click" then
  48.         --remove toggling and simplify button running
  49.         t.buttonList[p1].func()
  50.     end
  51. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement