Advertisement
Guest User

startup

a guest
Jan 20th, 2020
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.04 KB | None | 0 0
  1. local p = peripheral.wrap("left")
  2. if p == nil then
  3.   error("Error : no tank found")
  4. end
  5. local mon = peripheral.find("monitor")
  6. if mon ~= nil then
  7.   term.redirect(mon)
  8. end
  9.  
  10. local function getTankInfos(tab, infos)
  11.   for k,v in pairs(tab) do
  12.     if type(v) ~= "table" then
  13.       infos[k] = v
  14.      else
  15.        getTankInfos(v, infos)
  16.     end
  17.   end
  18. end
  19.  
  20. local function printAllAtt(tab)
  21.   for k,v in pairs(tab) do
  22.     print(k)
  23.     print(v)
  24.     print("___")
  25.   end
  26. end
  27.  
  28. local function main()
  29.   local tab = p.getTankInfo()
  30.   local infos = {}
  31.   getTankInfos(tab, infos)
  32.   --printAllAtt(infos)
  33.   --error()
  34.  
  35.   local capa = infos["capacity"]
  36.   local am = infos["amount"]
  37.   local percent
  38.   if am < 0.1 then
  39.     percent = 0
  40.   else
  41.     percent = am / capa * 100
  42.   end
  43.  
  44.   if mon ~= nil then
  45.     mon.clear()
  46.   end
  47.   print(infos["rawName"])
  48.   print()
  49.   print("Quantite :")
  50.   print(tostring(am/1000) .. " b")
  51.   print()
  52.   print("Remplit a :")
  53.   print(string.format("%.1f", percent) .. " %")
  54. end
  55.  
  56. while true do
  57.   main()
  58.   sleep(10)
  59. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement