Posted 09 January 2014 - 03:30 PM
Hi guys here I come again with some question :D/>.
I have this code to read the EU from MFSU and such AKA batbox_
and this is the main program:
when i run it, is says that "read_eu:6: attempt to concatenate nill and number."
even if I put the e 0,1 with "0","1" and such i get the same error :/
what should I do here guys
I have this code to read the EU from MFSU and such AKA batbox_
function read_eu(...)
local eu_stored = 0
local eu_total = 0
local args = {...}
for i=args[1],args[2] do
eu = peripheral.wrap(batbox_..i)
eu_stored = eu_stored + bat_box.getEnergyStored()
eu_total = eu_total + bat_box.getMaxEnergyStored()
end
return eu_stored, eu_total
end
and this is the main program:
local moni = peripheral.wrap("left")
moni.setTextScale(1.5)
function mon_limpar()
moni.clear()
moni.setCursorPos(1,1)
end
function newLine()
local_,cY = moni.getCursorPos()
moni.setCursorPos(1,cY+1)
end
function mj()
os.loadAPI("energia/read_mj")
local mj_avai, mj_total = read_mj.read_energy_cell()
os.unloadAPI("energia/read_mj")
perc = math.floor(100*mj_avai/mj_total)
moni.write("Mj on the House:")
newLine()
moni.write("Stored: "..mj_avai.."/"..mj_total.." at "..perc.."%")
return perc
end
-- to call the API to read the EU from MFSU and such
function eu(...)
local args = {...}
os.loadAPI("energia/read_eu")
local eu_avai, eu_total = read_eu.read_eu(args[1], args[2])
os.unloadAPI("energia/read_eu")
perc = math.floor(100*eu_avai/eu_total)
return eu_avai, eu_total, perc
end
-- Programa principal
while true do
mon_limpar()
local mj_p = mj()
os.loadAPI("energia/red_status")
local color = red_status.cor_ler("orange")
if mj_p <= 95 then
if color == false then
shell.run("redset","right","orange","true")
end
elseif mj_p == 100 then
if color == true then
shell.run("redset","right","orange","false")
end
end
os.unloadAPI("energia/red_status")
-- check EU on engine room
local eu_e_avai, eu_e_total, perc_e = eu(0,1)
newLine()
moni.write("EU from Engine room")
newLine()
moni.write("Stored: "..eu_e_avai.."/"..eu_e_total.." at "..perc_e.."%")
newLine()
newLine()
-- check EU on PC room
local eu_pc_avai, eu_pc_total, perc_pc = eu(2,3)
moni.write("Stored: "..eu_pc_avai.."/"..eu_pc_total.." at "..perc_pc.."%")
sleep(5)
end
when i run it, is says that "read_eu:6: attempt to concatenate nill and number."
even if I put the e 0,1 with "0","1" and such i get the same error :/
what should I do here guys