Skip to content

Commit c280f8b

Browse files
authored
Create progressBarEnergyExample.lua
1 parent 8326d02 commit c280f8b

1 file changed

Lines changed: 52 additions & 0 deletions

File tree

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
-- This is a example on how to use progressbars for energy. I used the Mekanism Ultimate Energy Cube.
2+
3+
4+
local filePath = "basalt.lua" --here you can change the file path default: basalt.lua
5+
if not(fs.exists(filePath))then
6+
shell.run("pastebin run ESs1mg7P "..filePath) -- this is an alternative to the wget command
7+
end
8+
local basalt = dofile(filePath) -- here you can change the variablename in any variablename you want default: basalt
9+
10+
local energyCube = peripheral.find("ultimateEnergyCube")
11+
12+
local main = basalt.createFrame("main"):show()
13+
14+
local progressText = main:addLabel("currentEnergyValue")
15+
:setText(0)
16+
:setForeground(colors.gray)
17+
:setBackground(false)
18+
:setPosition(10, 3)
19+
:setZIndex(6)
20+
:show()
21+
22+
local energyProgress = main:addProgressbar("mainEnergyCube")
23+
:setSize(20,3)
24+
:setPosition(2,2)
25+
:setBackground(colors.black)
26+
:setProgressBar(colors.green)
27+
:show()
28+
29+
energyProgress:onChange(function()
30+
local energy = tostring(energyCube.getEnergy())
31+
progressText:setText(energy)
32+
progressText:setPosition(energyProgress:getWidth()/2+1 - math.floor(energy:len()/2), 3)
33+
end)
34+
35+
36+
local function checkCurrentEnergy()
37+
while true do
38+
energyCube = peripheral.find("ultimateEnergyCube")
39+
if(energyCube~=nil)then
40+
local energyCalculation = energyCube.getEnergy() / energyCube.getMaxEnergy() * 100
41+
energyProgress:setProgress(energyCalculation)
42+
else
43+
energyProgress:setProgress(0)
44+
os.sleep(3)
45+
end
46+
os.sleep(1)
47+
end
48+
end
49+
50+
main:addThread("energyThread"):start(checkCurrentEnergy)
51+
52+
basalt.autoUpdate()

0 commit comments

Comments
 (0)