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

Displaying the Amount of Energy in an Energycell as Number and as Percentage

Started by xLife, 14 March 2014 - 05:02 PM
xLife #1
Posted 14 March 2014 - 06:02 PM
Hello, i'm very new to ComputerCraft and this is my first little program that shows the Energy stored in an Energycell (Thermalexpansion) with a percentage on an Monitor.

For Example:
SpoilerEnergycell 1: 200000 Redstone Flux 50%
Energycell 2: 400000 Redstone Flux 100%
Energycell 3: 300000 Redstone Flux 75%
Energycell 4: 100000 Redstone Flux 25%
Energycell 5: 150000 Redstone Flux 37,5%

Code (http://pastebin.com/r2GTYstx):

-- Energycells 1-5
con = {
  peripheral.wrap("cofh_thermalexpansion_energycell_17")
  peripheral.wrap("cofh_thermalexpansion_energycell_18")
  peripheral.wrap("cofh_thermalexpansion_energycell_19")
  peripheral.wrap("cofh_thermalexpansion_energycell_20")
  peripheral.wrap("cofh_thermalexpansion_energycell_21")
  }
-- Monitor
local mon = peripheral.wrap('right')
-- Reading the Amount of Energy
function getEnergy(Str)
  return con[Str].getEnergyStored("unknown")
end
-- Reading Max Energy
function getMaxEnergy(Str)
  return con[Str].getMaxEnergyStored("unknown")
end
-- Giving out a Percentage
function percent(minVal, maxVal)
  return math.floor((minVal/maxVal)*100)
end
-- Displaying the Amount of Energy and the Percentage of Energy on an monitor
while true do
  for i = 1, 5 do
	mon.setCursorPos((i*2)-1, 1)
	mon.write("Energycell "..i..": "..getEnergy(i).." Redstone Flux "..percent(getEnergy(i), getMaxEnergy(i)).."%")
sleep(1)
  end
end

My Problem is that i get this Error: bios:339: [string "startup"]:4: '}' expected (to close '{' at line 2)

Where is my Failure?

PS: Sorry for my bad english
Lyqyd #2
Posted 14 March 2014 - 06:42 PM
Table declarations require a comma before each value after the first, so put a comma at the end of each of the peripheral.wrap lines.
xLife #3
Posted 14 March 2014 - 08:19 PM
Thank you, works great now :D/>