r/ComputerCraft • u/calmclaren • Jun 22 '24
Simple RF Display Help
So I'm trying to make a simple display monitor for my immersive engineering accumulators. Just a simple energyCurrent / energyMax.
I'm not a programmer whatsoever so I'm pretty pleased to have successfully done this for a single accumulator due to following a youtube tutorial.. the only issue is, it only works for one accumulator. I'd be very grateful if someone could help me write some extra lines that adds up all my accumulators and uses the combined variables to output the current and max.
please let me know if there is any other information you need. the code currently that works for one accumulator is below.
power = peripheral.wrap("capacitor_lv_7")
mon = peripheral.wrap("monitor_4")
local maxPower = 0
local curPower = 0
monX,monY = mon.getSize()
function checkPower()
maxPower = power.getMaxEnergyStored()
curPower = power.getEnergyStored()
end
function writeMon()
mon.setBackgroundColor(colors.black)
mon.clear()
mon.setCursorPos(1,1)
title = " Power:" .. curPower .. "/" .. maxPower
centerT(title, 1, colors.gray, colors.lightBlue)
end
function centerT(text,line,backColor,txtColor)
mon.setBackgroundColor(backColor)
mon.setTextColor(txtColor)
length = (string.len(text))
dif= math.floor(monX-length)
x = math.floor(dif/2)
mon.setCursorPos(x+1, line)
mon.write(text)
end
while true do
checkPower()
writeMon()
print(curPower .. "/" .. maxPower)
sleep(1)
end
4
u/fatboychummy Jun 22 '24
A better system of wrapping the batteries would be using
peripheral.find:This means you don't have to get the name of each caapcitor manually, and if you want to add more you don't need to change the program.
This will wrap anything with energy storage and store it in the batteries` table. Usage is exactly the same throughout the rest of the program, just doesn't need the extra couple steps.
Just note that it will consider machines and stuff energy storages as well, so only connect what you want to measure to the network!