-1

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?

  • This is not a place for Minecraft questions. This question is off-topic. Please see http://stackoverflow.com/help/on-topic to see what type of questions are on topic for this site. Welcome to SO. – Bassinator Apr 12 '15 at 20:02
  • 1
    @HCBPshenanigans In my opinion this question is On-Topic! He don't ask about Minecraft. Even if his question is bad 'cause you can clearly see that he don't know what he does it's still On-Topic 'cause he askes about a problem with the scripting language Lua – Mischa Jul 30 '15 at 13:44

1 Answers1

1

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
Lee Yi
  • 517
  • 6
  • 17