robinvhoof
robinvhoof

Reputation: 1

ComputerCraft/BigReactors Energy Security System

I'm making a ComputerCraft program for the Big Reactors mod to make sure that I never run out of power. When I execute my program, I get an error: startup:7: attempt to compare __lt on nil and number. Here is my code:

reactor = peripheral.wrap("back")

    while getEnergyStored < 1000 do
        reactor.setActive = true

    while getEnergyStored > 9999999 do
         reactor.setActive = false
    end
end     

What am I doing wrong?

Upvotes: -1

Views: 757

Answers (1)

Lee Yi
Lee Yi

Reputation: 527

The error is telling you that getEnergyStored is not a number and cannot be compared using > with 1000.

I went to check the Big Reactors reference page and I think you are trying to use the function getEnergyStored. To do that, change it to getEnergyStored().

You need the two parentheses to tell the program to call the function instead of passing it as a variable.

Secondly, the program will not recognise getStoredEnergy() alone, because such a function belongs to your reactor variable.

Thirdly, setActive cannot be assigned to, it is a function. Call it like this: setActive(state) where state is either true or false.

I've rewritten your code to make it work

while true do
  --Get the stored energy count from the reactor
  local energy = reactor.getStoredEnergy()
  if energy < 1000 do
    reactor.setActive(true)
  else if energy > 9999999 do
    reactor.setActive(false)
  end
end

Upvotes: 1

Related Questions