Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal
  • 0
Amund211

Functions returning nil value

Question

Hi!

I'm having a problem I can't seem to wrap my head around.... I'm trying to use the Big Reactors Computer port, but every time I try to do something with it i.e. component.br_reactor.getEnergyStored, which reads total energy stored in the reactor, I get an error message saying:

Attempt to index 'component' (a nil value) (On line 1)

Here's the code:

power = component.br_reactor.getEnergyStored()
if power>5000000 then component.br_reactor.setActive(false) else component.br_reactor.setActive(true) end
sleep(1)

I attempt to do something(I have no idea what I'm doing), and add one line to the top.

local component = require component
power = component.br_reactor.getEnergyStored()
if power>5000000 then component.br_reactor.setActive(false) else component.br_reactor.setActive(true) end
sleep(1)

I now get the error message Syntax error near 'power'

 

The code is supposed to check if the EnergyStored is more than 500000 (half full) if it is deactivate the reactor, if not activate it.

 

Any tips will be gladly appreciated!

 

This is the first I've done within coding ever, apart from some HTML, so be gentle.

Link to post
Share on other sites

5 answers to this question

Recommended Posts

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.