Guest User

porter

a guest
Jun 12th, 2017
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.90 KB | None | 0 0
  1. os.loadAPI("button")
  2. dhd = peripheral.wrap("back")
  3. monitor = peripheral.wrap("right")
  4. locations = {}
  5. local page = 1
  6. local pages = 0
  7.  
  8. function dialLocation(info)
  9.   print(dhd.getStoredName(2))
  10.   outputLocations(locations[i])
  11.   dhd.terminate()
  12.   dhd.dialStored(info - 1)
  13. end
  14.  
  15. function generateLocations()
  16.   for i=0, address_count - 1 do
  17.     locations[i + 1] = dhd.getStoredName(i)
  18.   end
  19. end
  20.  
  21. function terminate()
  22.   dhd.terminate()
  23.   button.toggleButton("Terminate")
  24. end
  25.  
  26. function fillTable()
  27.   m.clear()
  28.   button.clearTable()
  29.   local totalrows = dhd.getStoredCount()
  30.   local col = 2
  31.   local row = 12
  32.   local countRow = 1
  33.   local currName = 0
  34.   local npp = 12
  35.   pages = math.ceil(totalrows/npp)
  36.   print("Total Rows: "..totalrows)
  37.   for o=1, address_count do
  38.     currName = currName + 1
  39.     if currName > npp*(page-1) and currName < npp*page+1 then
  40.       row = 4+(countRow)
  41.       locations[o] = string.sub(name, 0, 17)
  42.       button.setTable(string.sub(name, 0, 17), dialLocation, turt..":"..i, col, col+17, row, row)
  43.       if col == 21 then
  44.         col = 2
  45.         countRow = countRow+2
  46.       else
  47.         col = col+19
  48.       end
  49.     end
  50.   end
  51.   button.setTable("Next Page", nextPage, "", 21, 38, 1, 1)
  52.   button.setTable("Prev Page", prevPage, "", 2, 19, 1, 1)
  53.   button.setTable("Refresh", generateLocations, "", 21, 38, 19, 19)
  54.   button.setTable("Terminate", terminate, "", 2, 19, 19, 19)
  55.   button.label(15,3, "Page: "..tostring(page).." of "..tostring(pages))
  56.   button.screen()
  57. end
  58.  
  59. function nextPage()
  60.   if page+1 <= pages then page = page+1 end
  61.   fillTable()
  62. end
  63.  
  64. function prevPage()
  65.   if page-1 >= pages then page = page-1 end
  66.   fillTable()
  67. end
  68.  
  69. function getClick()
  70.   event, side, x,y = os.pullEvent()
  71.   if event == "monitor_touch" then
  72.     button.checkxy(x,y)
  73.   end
  74. end
  75.  
  76. address_count = dhd.getStoredCount()
  77. generateLocations()
  78. fillTable
  79.  
  80. while true do
  81.   getClick()
  82. end
Advertisement
Add Comment
Please, Sign In to add comment