Advertisement
jig487

tankController

Aug 2nd, 2021 (edited)
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.71 KB | None | 0 0
  1. local mon = peripheral.find("monitor")
  2. local tankList = peripheral.getNames()
  3. local blackList = {"back","right","top","left","bottom","front"}
  4. local oldTerm = term.redirect(mon)    
  5.  
  6. local function newButton(xStart,yStart,label)
  7.     term.setCursorPos(xStart,yStart)
  8.     term.write("["..label.."]")
  9.     local xEnd,yEnd = term.getCursorPos()
  10.     return {xStart, yStart, xEnd, yEnd, label}
  11. end
  12.  
  13. local function waitButtonPressed(list) --Returns index # of button pressed from button press
  14.     local event, side, x, y = os.pullEvent( "monitor_touch" )
  15.     for i = 1, #list do
  16.         if x >= list[i][1] and x <= list[i][3] and y >= list[i][2] and y <= list[i][4] then
  17.             return list[i][5]
  18.         end
  19.     end
  20.     return false
  21. end
  22.  
  23. mon.setBackgroundColor(colors.black)
  24. mon.setTextColor(colors.white)
  25. mon.clear()
  26. mon.setTextScale(0.5)
  27. mon.setCursorPos(1,1)
  28. local width,height = mon.getSize()
  29.  
  30. mon.write("Getting connected tanks...")
  31.  
  32. --Filter out non tank peripherals
  33. for i = #tankList, 1, -1 do
  34.     for j,filter in ipairs(blackList) do
  35.         if tankList[i] == filter then
  36.             table.remove(tankList, i)
  37.             break
  38.         end
  39.     end
  40. end
  41.  
  42. os.sleep(2)
  43. mon.clear()
  44. mon.setCursorPos(1,1)
  45. print("Found "..#tankList.." tanks:")
  46. print()
  47. for i,tankName in ipairs(tankList) do
  48.     print("["..i.."] "..tankName)
  49.     local x,y = mon.getCursorPos()
  50.  
  51. end
  52.  
  53. os.sleep(2)
  54. mon.clear()
  55. mon.setCursorPos(1,1)
  56. mon.setBackgroundColor(colors.orange)
  57. for i = 1, width do
  58.     mon.write(" ")
  59. end
  60. mon.setCursorPos(1,1)
  61. mon.setTextColor(colors.black)
  62. mon.write("Tank Controller")
  63. mon.setBackgroundColor(colors.black)
  64. mon.setTextColor(colors.white)
  65. mon.setCursorPos((width*0.5)-10,2)
  66. print("")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement