This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
starwind's profile picture

Questions about using CC to display 8 Energy cells information

Started by starwind, 23 June 2014 - 06:52 PM
starwind #1
Posted 23 June 2014 - 08:52 PM
Hey there ;)/>

Im just wondering if there is a way to have computercraft to show the power information of 8 energy cell combined on a monitor?

to make it so i can see how much power i have left without having to go down and clicking on every cell

maybe even getting it to show on those open pheriperal glasses aswell

Altho i'm very new to computercraft and dont really know how to write code, im wondering if this is even possible and if it is, is this something hard to learn to do?

perhaps there even is code upploaded somewhere, ( have been google'ing around abit with no luck )
GamerNebulae #2
Posted 23 June 2014 - 10:26 PM
It is possible, yes. It's actually very easy to do that. The problem is the way you want to visualize it. It's going to be very long and if an error occurs and you didn't make it "trial-and-error"-style, then you are going to have a bad time. If you upload some code, I will help you with that. If you want to see what methods are available, put a computer on the side of an energy cell, and type this (please change the side variable to the side the energy cell is on):

peripheral.getMethods(side)
That will print a table and you can pick two of the methods that have a very obvious name to what you wanna do.
starwind #3
Posted 23 June 2014 - 11:03 PM
Yeah have done that

getAdvancedMethodsData
getEnergyStored
getMaxEnergyStored

Problem is its 50 million RF or something in each energy cell, so printing the numbers would be a mess, maybe a bar would be better, but harder to do again i guess
GamerNebulae #4
Posted 24 June 2014 - 12:19 AM
I made an API for drawing bars on monitors… If you want it, grab it here on pastebin. Instructions on how to use:

os.loadAPI("/<program title>") --#Depends on you program title and where you stored it

<program title>.mCreateProgressBar("ID", "title", yTitle, "titleColor", value, maximum, yBar, barColor) 

Now, let's go over the variables:
ID: Needs to be a string, can be called whatever you want. DO NOT NAME DIFFERENT BARS THE SAME ID!
Title: Needs to be a string.
yTitle: Height of the title in numbers. DO NOT GIVE TWO BARS THE SAME Y VALUE!
titleColor: Needs to be a string and needs to be a color in the color-spectrum of CC.
value: For this, use <peripheralName>.getEnergyStored(). You can also use the peripheral.call() function.
maximum. For this, use <peripheralName>.getMaxEnergyStored(). You can also use the peripheral.call() function.
yBar: Height of the bar in numbers. DO NOT GIVE TWO BARS THE SAME Y VALUE!
barColor: Needs to be a string and needs to be a color in the color-spectrum of CC.
cptdeath58 #5
Posted 24 June 2014 - 12:30 AM
You could make a percentile of how much energy is stored to max energy allowed.
But if you use his API ^

cell = peripheral.wrap("Side")
local refreshRate = 5 -- change to any number
while true do
energy = cell.getEnergyStored
max = cell.getMaxEnergyStored
<program>.mCreateProgressBar("ID","Energy Stored", 1, "red", energy, max, 2, colors.blue )
sleep(refreshRate)
end
If that is how that works.
Edited on 23 June 2014 - 10:38 PM
starwind #6
Posted 24 June 2014 - 12:55 AM
ahh thank you! ;)/>

But how do i get all 8 or something cells to show as one bar? just hook up modem to all 8 and drag cable or wireless up to a computer with monitors attached?
Lyqyd #7
Posted 24 June 2014 - 02:30 AM
Yep, wired modems should allow you to deal with all of them. You'll still have to write the code to handle getting and presenting all of the data, of course.
starwind #8
Posted 24 June 2014 - 04:15 AM
ahh great
GamerNebulae #9
Posted 24 June 2014 - 10:22 AM
-snip-

One quick little note, he named every bar's ID, I think you can better name them "Cell_1", "Cell_2", etc…
cptdeath58 #10
Posted 02 July 2014 - 10:37 PM
-snip-

One quick little note, he named every bar's ID, I think you can better name them "Cell_1", "Cell_2", etc…

Well, that was just an example.