Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local side = "right" -- Change this to your peripheral side
- local device = peripheral.wrap(side)
- if not device then
- print("No peripheral found on " .. side .. "!")
- return
- end
- -- Attempt to get the fluid list
- local success, fluidList = pcall(device.listFluid)
- if not success or type(fluidList) ~= "table" then
- print("Error: listFluid() did not return a valid table.")
- return
- end
- -- Process fluid data
- local totalAmount = 0
- local fluidLines = {}
- for _, fluid in ipairs(fluidList) do
- if type(fluid.amount) == "number" then
- totalAmount = totalAmount + fluid.amount
- end
- table.insert(fluidLines, fluid.displayName .. ": " .. fluid.amount)
- end
- -- Add total amount at the end
- table.insert(fluidLines, "--------------------")
- table.insert(fluidLines, "Total Fluid Amount: " .. totalAmount)
- -- Scrollable output handling
- local outputOffset = 0
- local outputPageSize = 10 -- Lines per page
- local function displayOutput()
- term.clear()
- term.setCursorPos(1,1)
- print("Fluid Storage List (Scroll Up/Down):\n")
- for i = 1, outputPageSize do
- local index = i + outputOffset
- if index > #fluidLines then break end
- print(fluidLines[index])
- end
- print("\nScroll Up/Down to navigate, Q to exit.")
- end
- displayOutput()
- while true do
- local event, key = os.pullEvent()
- if event == "mouse_scroll" then
- if key == 1 and outputOffset + outputPageSize < #fluidLines then
- outputOffset = outputOffset + 1
- elseif key == -1 and outputOffset > 0 then
- outputOffset = outputOffset - 1
- end
- displayOutput()
- elseif event == "key" then
- if key == keys.q then break -- Exit on 'Q'
- elseif key == keys.down and outputOffset + outputPageSize < #fluidLines then
- outputOffset = outputOffset + 1
- displayOutput()
- elseif key == keys.up and outputOffset > 0 then
- outputOffset = outputOffset - 1
- displayOutput()
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement