This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Pjevser's profile picture

Tank Read And Redstone.setoutput Problem

Started by Pjevser, 11 September 2013 - 11:01 AM
Pjevser #1
Posted 11 September 2013 - 01:01 PM
So i'm trying to make my code change redstone.setOutput on or off depening if my tank is full or not.
When i start my program and my tank is full it will keep redstone off, but if i take some liquid out of my tank it still says it's full with 720000 inside it.
Not sure what i'm doing wrong so i hope someone can help me spot the problem. I'm new to computercraft. :)/>

local valve = peripheral.wrap("left")
local tableInfo = valve.getTanks("unknown")
while true do

  for k, v in pairs(tableInfo) do
    for x, y in pairs(v) do
      if x == "amount" then
        if (y == 720000) then
          redstone.setOutput("right", false)
        elseif (y < 720000) then
          redstone.setOutput("right", true)
        end
      end
    end
  end
  os.sleep(10)
end

So my code is there, but whenever my liquid gets below 720000 it doesn't turn on redstone signal, and if i stop the program and start it again it will fine actiave the redstone signal, but then when the tank is full it wont turn it off again :(/>
OmegaVest #2
Posted 11 September 2013 - 03:45 PM
You initialize tableInfo outside the while loop. So it will always check the same result, instead of getting a new result. Move tableInfo = valve.getTanks("unknown") in to the while loop.
Pjevser #3
Posted 11 September 2013 - 03:54 PM
You initialize tableInfo outside the while loop. So it will always check the same result, instead of getting a new result. Move tableInfo = valve.getTanks("unknown") in to the while loop.
Ah :)/> Ty didnt know that haha. But now i do know till next time :D/>