Posted 01 December 2015 - 09:17 PM
EDIT: Now using peripheral.call rather than wrapping the variable.
THIS TOPIC CAN BE CLOSED.
Should get all connected energy cells, then get their current energy and add it to the variable to get the max energy. I'm wrapping the peripheral correctly although it still gives an error at line 27: attempt to index a nil value, aka it hasn't been wrapped.
THIS TOPIC CAN BE CLOSED.
Should get all connected energy cells, then get their current energy and add it to the variable to get the max energy. I'm wrapping the peripheral correctly although it still gives an error at line 27: attempt to index a nil value, aka it hasn't been wrapped.
periph = peripheral.getNames()
res = {}
for i=0, #periph do
if string.sub(tostring(periph[i]), 1, 40) == "tile_thermalexpansion_cell_resonant_name" then
table.insert(res, periph[i])
end
end
function reDraw(curPower, maxPower)
percent = math.floor( (curPower / maxPower) * 100 )
term.clear()
term.setCursorPos(1,1)
term.setTextColor(colors.red)
print("Power: "..curPower)
term.setTextColor(colors.orange)
print("Max power: "..maxPower)
term.setTextColor(colors.lime)
print(percent.."%")
end
while true do
power = 0
maxPower = 0
for i=0, #res do
curPeriph = peripheral.wrap(tostring(res[i]))
cellMaxPower = curPeriph.getMaxEnergyStored()
cellPower = curPeriph.getEnergyStored()
power = power + cellPower
maxPower = maxPower + cellMaxPower
end
reDraw(power, maxPower)
end
Edited on 01 December 2015 - 08:33 PM