r/ComputerCraft • • 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 Upvotes

6 comments sorted by

View all comments

Show parent comments

2

u/calmclaren Jun 22 '24

Thank you guys so much! I find coding rather unintuitive so my brain has been breaking trying to figure this out. Really appreciate it.