xo33ab

tables

Nov 25th, 2023 (edited)
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.44 KB | None | 0 0
  1. local t = {
  2.     ["purple"] = {
  3.         side = "left",
  4.         flux_level = 0,
  5.         flux_max = 7
  6.     },
  7.  
  8.     ["lime"] = {
  9.         side = "back",
  10.         flux_level = 0,
  11.         flux_max = 7
  12.     },
  13.  
  14.     ["orange"] = {
  15.         side = "right",
  16.         flux_level = 0,
  17.         flux_max = 7
  18.     },
  19.  
  20.     ["central"] = {
  21.         side = "front",
  22.         flux_level = 0,
  23.         flux_max = 5
  24.     }
  25. }
  26. ---------------------------
  27. --Prints Table for debugging
  28. ---------------------------
  29. local function printTable(e)
  30.     if type(e) == "table" then
  31.         for k,v in pairs(e) do -- for every element in the table
  32.             print(k,v)
  33.             printTable(v)       -- recursively repeat the same procedure
  34.             sleep(1.5)
  35.             print()
  36.  
  37.         end
  38.     else -- if not, we can just print it
  39.         print(e)
  40.     end
  41. end
  42. ---------------------------
  43. --U
  44. ---------------------------
  45. local function getUpdate()
  46.     while true do
  47.         if os.pullEvent("redstone") then
  48.             t.purple.flux_level = rs.getAnalogInput(t.purple.side)
  49.             t.lime.flux_level = rs.getAnalogInput(t.lime.side)
  50.             t.orange.flux_level = rs.getAnalogInput(t.orange.side)
  51.             t.central.flux_level = rs.getAnalogInput(t.central.side)
  52.             print("Updated")
  53.             printTable(t)
  54.             sleep(1)
  55.         else
  56.             sleep(1)
  57.             print("No Update")
  58.         end
  59.     end
  60. end
  61.  
  62. getUpdate()
  63.  
Advertisement
Add Comment
Please, Sign In to add comment