Minecraft Version: 1.12.2
ComputerCraft Version: 1.89.2
I am trying to use ComputerCraft to read tank data from OpenBlocks tanks and output the fluid amount onto a monitor. Although it's not working and I am running into the issue where my code is not outputting an amount and just outputs 0. What am I doing wrong?
I would also like to figure out how to automatically read the tanks metadata to pull the fluid type automatically instead of me creating a fixed variable. Thanks!
Here is my setup:
https://imgur.com/a/K69n697
Here is my code:
fluidtype = "Gaseous Fuel"
temperature = "21" -- This is going to be used for something else later on, it's currently just a placeholder.
tanks = {}
for i,v in ipairs(peripheral.getNames()) do
if peripheral.getMethods(v).tanks then
table.insert(tanks, peripheral.wrap(v))
end
end
monitor = peripheral.find("monitor")
while true do
sleep(.1)
fluidamount = 0
for _,tank in ipairs(tanks) do
local fluids = tank.tanks()
if fluids then
for _,fluid in ipairs(fluids) do
fluidamount = fluidamount + fluid.amount
end
end
end
monitor.clear()
monitor.setCursorPos(1, 1)
monitor.write("Type: "..fluidtype)
monitor.setCursorPos(1, 3)
monitor.write("Fill: "..fluidamount.."mB")
monitor.setCursorPos(1, 5)
monitor.write("Temp: "..temperature.."°C")
end
Try putting some print statements in your code and checking if the program is flowing as you expect it (e.g. if statements give true and their body runs).
I have the feeling that fluids might be a table that has string keys and thus needs pairs instead of pairs for the for loop.
I forget how stuff worked back in 1.12 so my advice is going to be limited.