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

[Automatic EnergyCell refill] I need a fresh eye here.

Started by plazter, 08 December 2013 - 12:32 PM
plazter #1
Posted 08 December 2013 - 01:32 PM
Automatic Energy Cell refilling system

Hello out there! ;)/>
So.. i made this code for a friend yesterday, and it didnt really work out as it was suppose to do, so i began to make a new, but i keep hitting the same wall, i've tryed to walk around to issue by saying it to do it in another way..

the code is simple enough:p
Spoiler


local c = peripheral.wrap("bottom")

local function cell()
	 if c.getEnergyStored() < 500000 then
		 rs.setBundledOutput("back", 1)
	elseif c.getEnergyStored() == c.getMaxEnergyStored() then
		rs.setBundledOutput("back", 0)
		sleep(10)
   end
end

while true do
  cell()
  term.clear()
  term.setCursorPos(1,1)
  print("Energy cell management")
  sleep(2)
end


i get the error message: Attempt to compare number with string expected, got string

Please help me out here.. i dont understand it since i would mean it's simple enough and should work just fine?

Regards Plazter
Bomb Bloke #2
Posted 09 December 2013 - 02:19 AM
Beats me as to why, but wrapping a redstone energy cell and running "type(c.getEnergyStored())" indeed returns "string". "c.getMaxEnergyStored()" gives a number (as one would expect).

Using the term "tonumber(c.getEnergyStored())" should do the trick.
plazter #3
Posted 15 December 2013 - 11:45 AM
Beats me as to why, but wrapping a redstone energy cell and running "type(c.getEnergyStored())" indeed returns "string". "c.getMaxEnergyStored()" gives a number (as one would expect).

Using the term "tonumber(c.getEnergyStored())" should do the trick.

Tryed aswell, same error .. got it working but not really reacting :P/>