Advertisement
nintendowfi

Text output and hrly coal production

Aug 5th, 2022 (edited)
1,363
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.46 KB | None
  1. rednet.open("left")
  2. mon = peripheral.wrap("right")
  3.  
  4. local total_counted = 0
  5. local counted_hour = 0
  6. local old_total_counted = 0
  7. local lst_of_counted = {}
  8. local cycle = 0
  9.  
  10. function sum(t)
  11.     local sum = 0
  12.     for k,v in pairs(t) do
  13.         sum = sum + v
  14.     end
  15.  
  16.     return sum
  17. end
  18.  
  19.  
  20. while true do
  21.    
  22.     local currently_counted = 0
  23.    
  24.     x,y,z = rednet.receive()
  25.    
  26.     old_total_counted = total_counted
  27.     table.insert(lst_of_counted,old_total_counted)
  28.     cycle = cycle+1
  29.     total_counted = y
  30.     currently_counted = y - old_total_counted
  31.    
  32.     if cycle > 11 then
  33.         table.remove(lst_of_counted, 1)
  34.         --delete last item of table and then sum together all
  35.         counted_hour = sum(lst_of_counted)
  36.         end
  37.  
  38.     mon.clear()
  39.     print("+-------------------------------------+")
  40.     print("\n")
  41.     print("\nWe have produced a total of", total_counted, "pieces of coal!\n")
  42.     print(total_counted,"makes", math.floor(total_counted/64),"stacks of coal!\n")
  43.     print("In the last batch there was", currently_counted, "pieces of coal!\n")
  44.     if cycle > 10 then
  45.         print("In the last hour we have produced", counted_hour,"pieces of coal!")
  46.         print("\n")
  47.         print("\n")
  48.         print("+-------------------------------------+")
  49.     else do
  50.         print("In the last hour we have produced [N/A] pieces of coal!") end
  51.         print("\n")
  52.         print("\n")
  53.         print(lst_of_counted)
  54.         print("+-------------------------------------+")
  55.     end
  56. end
  57.  
Advertisement
RAW Paste Data Copied
Advertisement