Jump to content




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


  • You cannot reply to this topic
2 replies to this topic

#1 xLife

  • Members
  • 7 posts
  • LocationGermany

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:
Spoiler

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

#2 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

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.

#3 xLife

  • Members
  • 7 posts
  • LocationGermany

Posted 14 March 2014 - 08:19 PM

Thank you, works great now :D





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users