Advertisement
Guest User

startup

a guest
Nov 22nd, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.81 KB | None | 0 0
  1. function periUptd()
  2.  
  3.   tanks = {{},{}} -- Number of '{}' must match the number of liquids
  4.  
  5.   -- Create adress array
  6.   -- tanks[ liquidNumber ][ tankNumber ] = peripheral.wrap( tank address )
  7.  
  8.  
  9. end
  10.  
  11. periUptd()
  12.  
  13. -- Assign terminal glasses bridge adress
  14. glass = peripheral.wrap("openperipheral_bridge_0")
  15.  
  16. -- Number of liquids
  17. liquids = 2
  18. -- Possition of text {firstLiquid, secondLiquid, ...}
  19. Xpos = {5, 5}
  20. Ypos = {5, 15}
  21. -- Color of text (in HEX) {firstLiquid, secondLiquid, ...}
  22. color = {0xff8800, 0x0000ff}
  23.  
  24.  
  25. function tankInfo()
  26.  
  27.   tankNum = {}
  28.   tanksInfo = {}
  29.  
  30.   for i = 1, liquids, 1 do
  31.     tanksInfo[i] = {}
  32.     tankNum[i] = 0
  33.     num = 1
  34.     while true do
  35.       if tanks[i][num] == nil then
  36.         break
  37.       end
  38.       num = num+1
  39.       tankNum[i] = tankNum[i]+1
  40.     end
  41.  
  42.     for num = 1, tankNum[i] do
  43.       tanksInfo[i][num] = tanks[i][num].getTankInfo()
  44.     end
  45.    
  46.   end
  47.  
  48.  
  49. end
  50.  
  51. function clear()
  52.   term.setCursorPos(1, 1)
  53.   term.clear()
  54. end
  55.  
  56. tankInfo()
  57.  
  58. function tanksCap()
  59.   capacity = {}
  60.  
  61.   for i = 1, liquids do
  62.     capacity[i] = 0
  63.     for num = 1, tankNum[i] do
  64.       capacity[i] = capacity[i] + tanksInfo[i][num][1].capacity
  65.     end
  66.  
  67.     capacity[i] = capacity[i] / 1000
  68.   end
  69. end
  70.  
  71. function tanksAmo()
  72.   amount = {}
  73.  
  74.   for i = 1, liquids do
  75.     amount[i] = 0
  76.  
  77.     for num = 1, tankNum[i] do
  78.       if tanksInfo[i][num][1].contents then
  79.         amount[i] = amount[i] + tanksInfo[i][num][1].contents.amount
  80.       end
  81.     end
  82.  
  83.     amount[i] = amount[i] / 1000
  84.   end
  85. end
  86.  
  87.  
  88. while true do
  89.  
  90.   periUptd()
  91.  
  92.   tankInfo()
  93.  
  94.   tanksCap()
  95.  
  96.   tanksAmo()
  97.  
  98.   clear()
  99.   glass.clear()
  100.   for i = 1, liquids do
  101.     glass.addText(Xpos[i], Ypos[i], amount[i] .. "/" .. capacity[i], color[i])
  102.   end  
  103.   glass.sync()
  104.   sleep(0.5)
  105. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement