Advertisement
Guest User

porter

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