Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tArgs = {...}
- local dir = tonumber(tArgs[1]) --valve Direction
- local warning = tonumber(tArgs[2]) -- Warning level in %
- -- Valve and output
- local tank = peripheral.wrap(dir)
- local cap -- Tank capacity
- local amount -- Amount liquid in tank
- local percentfull -- Percent liquid in tank
- local lastpercent = 100 -- Percent last loop
- local sleeptime -- How long to sleep
- --redstone.setOutput("left", false)
- function getTank(tankPeriph)
- local tableInfo = tankPeriph.getTankInfo(dir) -- Local to the getTank function.
- for k,v in pairs(tableInfo) do
- fluidRaw = v.rawName -- local to this for loop
- fluidName = v.name -- local to this for loop
- fluidAmount = v.amount -- local to this for loop
- fluidCapacity = v.capacity -- local to this for loop
- end
- return fluidRaw, fluidName, fluidAmount, fluidCapacity -- Returning the values of global variables (which are nil).
- end
- -- Main prog loop, never stop
- while true do
- -- Fill table with data from tank valve
- local fluidRaw, fluidName, fluidAmount, fluidCapacity = getTank(tank)
- if fluidName then
- -- Get values for tank capacity and amount
- fluidName = string.gsub(fluidName, "^%l", string.upper)
- cap = fluidCapacity / 1000
- amount = fluidAmount
- -- If tank is empty, to avoid math issues with 0
- if amount == nil then
- amount = 0
- percentfull = 0
- else
- -- Use math.floor to convert to integers
- amount = math.floor(amount / 1000)
- percentfull = math.floor(100 * amount / cap)
- end
- term.clear()
- print(fluidName)
- print(amount)
- print(percentful)
- sleeptime = 10
- end -- ends if fluidname
- sleep(sleeptime)
- end --ends while true loop
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement