Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --CODE NOT MEANT TO RUN, JUST EXAMPLE SNIPPETS
- --for things which return 1 table (like sensor):
- local tile = peripheral.wrap("some_tile")
- for k,v in pairs(tile) do
- print(k)
- end
- --for things which return nested tables (like tanks):
- tank = peripheral.wrap("back") --or w/e side your thing is on
- results = tank.getTankInfo("back") --"unknown" will also work here
- for k,_ in pairs(results) do
- for i,v in pairs(results[k]) do
- print(i..v)
- end
- end
- --for most tanks, everything will be in the first nested table, so you can:
- tank = peripheral.wrap("back")
- tankInfo = tank.getTankInfo("unknown")[1] --the [1] access the first table so you don't have to later
- local fluidAmount = tankInfo.amount
- --if no fluid, this will return nil.
- --Can't do arithmetic with nil, so check if it is a nil (nil = false) and if so, set to 0
- if not fluidAmount then
- fluidAmount = 0
- end
- print("Amount: ", fluidAmount)
- local tankCapacity = tankInfo.capacity
- --will always return a capacity if there is a valid tank so no correction needed
- print("Capacity: ", tankCapacity)
- local percent = math.round(fluidAmount/tankCapacity*100, 1) --round to nearest decimal
- print("Percent Filled: ", percent)
Advertisement
Add Comment
Please, Sign In to add comment