Posted 04 October 2013 - 03:35 PM
Hello. I wrote that code for a Computer to connect to Ender Tank on it's left and to empty part of it's content (Ender Tanks auto-eject when they receive redstone signal):
It's reading that amount correctly and emptying… Only on first time. The next, it's printing that same value all over again and it's still toggling that redstone (no more fluid) or is not doing anything (overflow on the other side). What am I doing wrong here? I though about making TankSize as local variable, but I don't know how, since I have to use a function to even get that value, and getting out of that function deletes local, if I remember correctly (and if Computer saying "nil" after try with that is telling me correctly).
Spoiler
local p = peripheral.wrap("left")
local TankInfo = p.getTanks("left")
--[[
for key,value in pairs(TankInfo) do
for key2,value2 in pairs(value) do
print(key.."| "..key2..": "..tostring(value2))
end
end
--]]
function checkAmount()
for i,j in pairs(TankInfo) do
TankSize = j["amount"]
end
end
function Tank()
checkAmount()
print(TankSize)
if TankSize > 14000 then
redstone.setOutput("left", true)
sleep(5)
redstone.setOutput("left", false)
elseif TankSize < 1400 then
redstone.setOutput("left", false)
sleep(5)
end
TankSize = 0
end
while true do
checkAmount()
Tank()
sleep(60)
end
It's reading that amount correctly and emptying… Only on first time. The next, it's printing that same value all over again and it's still toggling that redstone (no more fluid) or is not doing anything (overflow on the other side). What am I doing wrong here? I though about making TankSize as local variable, but I don't know how, since I have to use a function to even get that value, and getting out of that function deletes local, if I remember correctly (and if Computer saying "nil" after try with that is telling me correctly).