Jump to content




Questions about using CC to display 8 Energy cells information


9 replies to this topic

#1 starwind

  • Members
  • 8 posts

Posted 23 June 2014 - 07: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 )

#2 GamerNebulae

  • Members
  • 216 posts
  • LocationNetherlands

Posted 23 June 2014 - 09: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.

#3 starwind

  • Members
  • 8 posts

Posted 23 June 2014 - 10: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

#4 GamerNebulae

  • Members
  • 216 posts
  • LocationNetherlands

Posted 23 June 2014 - 11:19 PM

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.

#5 cptdeath58

  • Members
  • 139 posts
  • LocationError 404: Could not find.

Posted 23 June 2014 - 11:30 PM

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 by cptdeath58, 23 June 2014 - 11:38 PM.


#6 starwind

  • Members
  • 8 posts

Posted 23 June 2014 - 11:55 PM

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?

#7 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 24 June 2014 - 01: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.

#8 starwind

  • Members
  • 8 posts

Posted 24 June 2014 - 03:15 AM

ahh great

#9 GamerNebulae

  • Members
  • 216 posts
  • LocationNetherlands

Posted 24 June 2014 - 09:22 AM

View Postcptdeath58, on 23 June 2014 - 11:30 PM, said:

-snip-

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

#10 cptdeath58

  • Members
  • 139 posts
  • LocationError 404: Could not find.

Posted 02 July 2014 - 09:37 PM

View PostGamerNebulae, on 24 June 2014 - 09:22 AM, said:

View Postcptdeath58, on 23 June 2014 - 11:30 PM, said:

-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.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users