Advertisement
feedmecookies

Testing tables

Nov 20th, 2020 (edited)
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.56 KB | None | 0 0
  1. --TouchPc API--
  2. button = {}
  3. CurrentPage = 2
  4.  
  5. pp = peripheral.isPresent("top")
  6. if pp then
  7. m = peripheral.wrap("top")
  8. end
  9.  
  10.  
  11. floppy = false --Currently does nothing, but is going to be used in a later release to be able to save and retrieve the status on each button on load/exit--
  12.  
  13. function ChangePeripheral()
  14. end
  15.  
  16. function CreateButton(Id,MinX,MaxX,MinY,MaxY,Text,Function,Color,State,Page,...)
  17. -- Create a list of buttons and their variables --
  18. button[Id] = {}
  19. button[Id][1] = MinX
  20. button[Id][2] = MaxX
  21. button[Id][3] = MinY
  22. button[Id][4] = MaxY
  23. button[Id][5] = Text
  24. button[Id][6] = Function
  25. button[Id][7] = Color
  26. button[Id][8] = State
  27. button[Id][9] = Page
  28. button[Id][10] = ...
  29. end
  30.  
  31.  
  32.  
  33.  
  34. function CheckButtons() --eventc is used to define whether it is a monitor event or a terminal event.--
  35. -- Checks if the the player clicked a button--
  36.  
  37.  
  38.  
  39. --Change it to be able to distinguish what page the button is on
  40.  
  41.  
  42.  
  43. if pp == true then
  44. event, side, x, y = os.pullEvent("monitor_touch")
  45. else
  46. event, side, x, y = os.pullEvent("mouse_click")
  47. end
  48.  
  49.  
  50.  
  51. for i = 1, table.getn(button) do
  52. if x >= button[i][1] and x <= button[i][2] and y >= button[i][3] and y <= button[i][4] and button[1][9] == CurrentPage then
  53. if button[i][8] == "on" then
  54. button[i][8] = "off"
  55. button[i][10]()
  56. elseif button[i][8] == "off" then
  57. button[i][8] = "on"
  58. button[i][6]()
  59. elseif button[i][8] == "none" then
  60. button[i][6]()
  61. end
  62. sleep(0.1)
  63. end
  64. end
  65. end
  66.  
  67. function DrawButton()
  68. --draws the button on the screen--
  69.  
  70. for i = 1, table.getn(button) do
  71. if button[i][9] == CurrentPage then
  72. if pp == true then
  73. m.setBackgroundColor(button[i][7])
  74. else
  75. term.setBackgroundColor(button[i][7])
  76. end
  77. for y = button[i][3], button[i][4] do
  78. for x = button[i][1], button[i][2] do
  79. if pp == true then
  80. m.setCursorPos(x,y)
  81. m.write(" ")
  82. else
  83. term.setCursorPos(x,y)
  84. term.write(" ")
  85. end
  86. end
  87. end
  88. end
  89. end
  90. end
  91. function NextPage(PageNumber)
  92. --for when you use a too many buttons to be shown in one screen--
  93. end
  94.  
  95. function DialogBox(message)
  96. --enables the use of dialog boxes--
  97. end
  98.  
  99. function SaveTo(info,file)
  100. -- in the case you would like to save a information to a file(especially useful to save dialog box messages) --
  101. end
  102.  
  103.  
  104.  
  105. --only on offical release--
  106. --os.pullEvent = os.pullEventRaw--
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement