Posted 06 November 2013 - 07:27 AM
Hello guys:
a short question, i think the answer is pretty easy, but i cannot find my mistake:
this code:
is working as intended (0 errors) if there is any amount > 0 in the tank, so i tried to get rid of the nil problem with:
but here i get always "empty" regardless the amount in it
my thoughts:
* why is in the first code the if - function progressing to "then" and in the 2nd to "else" but i changed nothing in the tank
* if the tank is empty there is no x=="amount" in the table, so the if-function should proceed to "else", or?
* i cannot set y==0 or y==nil or y>0 because if there is no amount in the tank the if - function with x=="amount" is not triggering, or?
How can i bypass this problem?
And a short second question:
can i compare the y-value from each loop? – so that a message or what else is only sent, if the value(amount) changed?
Thx in advance
Wiesl
a short question, i think the answer is pretty easy, but i cannot find my mistake:
this code:
tank = peripheral.wrap("bottom")
modem = peripheral.wrap("back")
modem.open(1)
while true do
tableInfo = tank.getTanks("unknown")
for key,value in pairs(tableInfo) do
for x,y in pairs(value) do
if x == "amount" then
percent = math.floor(y / 576000 * 100)
print(percent, "%")
modem.transmit(1, 1, percent)
end
end
end
sleep(2)
end
is working as intended (0 errors) if there is any amount > 0 in the tank, so i tried to get rid of the nil problem with:
tank = peripheral.wrap("bottom")
modem = peripheral.wrap("back")
modem.open(1)
while true do
tableInfo = tank.getTanks("unknown")
for key,value in pairs(tableInfo) do
for x,y in pairs(value) do
if x == "amount" then
percent = math.floor(y / 576000 * 100)
print(percent, "%")
modem.transmit(1, 1, percent)
else
print("empty")
sleep(10)
end
end
end
sleep(2)
end
but here i get always "empty" regardless the amount in it
my thoughts:
* why is in the first code the if - function progressing to "then" and in the 2nd to "else" but i changed nothing in the tank
* if the tank is empty there is no x=="amount" in the table, so the if-function should proceed to "else", or?
* i cannot set y==0 or y==nil or y>0 because if there is no amount in the tank the if - function with x=="amount" is not triggering, or?
How can i bypass this problem?
And a short second question:
can i compare the y-value from each loop? – so that a message or what else is only sent, if the value(amount) changed?
Thx in advance
Wiesl