Posted 25 December 2013 - 04:27 AM
Hey Guys,
I've got a problem with my rounding function and it doesn't seem to work with the data it receives from the tanks. I'm pretty much sure that it reads the tanks properly as I have tested it several times in the lua prompt. It also worked in other programs. But somehow the rounding function cannot operate with it.
If anyone could tell me what I did wrong I'd be very happy.
Thank you!
Igel
local function round(num,idp)
local mult = 10^(idp or 0)
return math.floor(num * mult + 0.5)/mult
end
local function oilTank()
local otank = peripheral.wrap("steel_tank_valve_3")
local oinfo = otank.getTanks("unknown")[1]
local oamount = oinfo["amount"]
local ocapacity = oinfo["capacity"]
if amount == nil then
local ot = 0
else
local ot = (oamount/ocapacity)*100
end
local opt = round(ot, 2)
return opt
end
local function fuelTank()
local ftank = peripheral.wrap("steel_tank_valve_0")
local finfo = ftank.getTanks("unknown")[1]
local famount = finfo["amount"]
local fcapacity = finfo["capacity"]
if famount == nil then
local ft = 0
else
local ft = (famount/fcapacity)*100
end
local fpt = round(ft, 2)
return fpt
end
local function mon()
local m = peripheral.wrap("monitor_3")
return m
end
while true do
local oil = oilTank()
local fuel = fuelTank()
m = mon()
m.setTextScale(1.5)
m.clear()
m.setCursorPos(1,1)
m.write("Oil: "..oil.." %")
m.setCursorPos(1,2)
m.write("Fuel: "..fuel.." %")
end
[/php]
I've got a problem with my rounding function and it doesn't seem to work with the data it receives from the tanks. I'm pretty much sure that it reads the tanks properly as I have tested it several times in the lua prompt. It also worked in other programs. But somehow the rounding function cannot operate with it.
If anyone could tell me what I did wrong I'd be very happy.
Thank you!
Igel
Spoiler
[php]rednet.open("top")local function round(num,idp)
local mult = 10^(idp or 0)
return math.floor(num * mult + 0.5)/mult
end
local function oilTank()
local otank = peripheral.wrap("steel_tank_valve_3")
local oinfo = otank.getTanks("unknown")[1]
local oamount = oinfo["amount"]
local ocapacity = oinfo["capacity"]
if amount == nil then
local ot = 0
else
local ot = (oamount/ocapacity)*100
end
local opt = round(ot, 2)
return opt
end
local function fuelTank()
local ftank = peripheral.wrap("steel_tank_valve_0")
local finfo = ftank.getTanks("unknown")[1]
local famount = finfo["amount"]
local fcapacity = finfo["capacity"]
if famount == nil then
local ft = 0
else
local ft = (famount/fcapacity)*100
end
local fpt = round(ft, 2)
return fpt
end
local function mon()
local m = peripheral.wrap("monitor_3")
return m
end
while true do
local oil = oilTank()
local fuel = fuelTank()
m = mon()
m.setTextScale(1.5)
m.clear()
m.setCursorPos(1,1)
m.write("Oil: "..oil.." %")
m.setCursorPos(1,2)
m.write("Fuel: "..fuel.." %")
end
[/php]