Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local meBridge = peripheral.wrap("left") -- Connect to ME Bridge on the left side
- local monitor = peripheral.find("monitor") -- Find a connected monitor
- if not meBridge then
- print("Error: ME Bridge not found on the left side!")
- return
- else
- print("ME Bridge successfully detected!")
- end
- if not monitor then
- print("Error: No monitor found!")
- return
- else
- print("Monitor successfully detected!")
- monitor.setTextScale(1) -- Set text scale for better visibility
- end
- -- Function to safely print table contents without serialization issues
- function printTable(tbl, indent)
- indent = indent or ""
- for k, v in pairs(tbl) do
- if type(v) == "table" then
- print(indent .. tostring(k) .. " = {")
- printTable(v, indent .. " ")
- print(indent .. "}")
- else
- print(indent .. tostring(k) .. " = " .. tostring(v))
- end
- end
- end
- -- Function to calculate total item count safely
- function getTotalItemCount()
- local items = meBridge.listItems()
- if not items or type(items) ~= "table" then
- print("No items detected in ME system or invalid data!")
- return 0
- end
- local total = 0
- for _, item in pairs(items) do
- if type(item) == "table" and type(item.amount) == "number" then
- total = total + item.amount
- else
- print("Warning: Skipping invalid item entry:")
- printTable(item, " ")
- end
- end
- return total
- end
- -- Function to update the monitor display
- function updateMonitor(total)
- monitor.clear()
- monitor.setCursorPos(1, 1)
- monitor.write("Total Items in ME System:")
- monitor.setCursorPos(1, 3)
- monitor.write(tostring(total))
- end
- -- Debugging: Print the list of items in a safe way
- print("Debug: Raw ME System Data")
- local items = meBridge.listItems()
- if items and type(items) == "table" then
- printTable(items)
- else
- print("Invalid or empty item list.")
- end
- -- Continuously update the monitor and print to terminal
- while true do
- local totalCount = getTotalItemCount()
- print("Total Items in ME System: " .. tostring(totalCount))
- updateMonitor(totalCount)
- sleep(5) -- Updates every 5 seconds
- end
Advertisement
Add Comment
Please, Sign In to add comment