0

I'm using this code from How do I detect if MFSU has half below energy, from an answer about half way down the page:

mfe = peripheral.wrap("left")
while true do
  euPercent = mfe.getEUStored() / mfe.getEUCapacity()
  if euPercent==1 then
    redstone.setOutput("right", false)
  elseif euPercent<=.5 then
    redstone.setOutput("right", true)
  end
  sleep(1)
end

This is so that I can have my computer turn off my nuclear reactor when it's full of power and on when it's not full, but when I run the program it says

reactor:3: attempt to index ? (a nil value)
  • this is where i got the code from gaming.stackexchange.com/questions/162187/… its about half way down the page – Quelia Feb 15 '15 at 22:09
  • is side a valid value? Shouldn't it be left or right? – kutschkem Feb 15 '15 at 22:33
  • Sorry about that, forgot to mention that i did replace the side parts of the code. This is what it looks like in my computer [IMG]i60.tinypic.com/i3cgb7.png[/IMG] i still get the error – Quelia Feb 15 '15 at 22:43
  • Have you tried changing left and right? Maybe you just got it the wrong way around. – kutschkem Feb 16 '15 at 7:53
3

periphera.wrap() is returning nil and storing that in mfe. That's a problem, and why it fails to be useful when you try to access it on line 3.

It's hard to figure out why from a distance. Three reasons I can think of are:

  1. That the "side" argument to wrap() is incorrect and there's nothing on that side, which would make the API deliberately return nil to alert you to the lack of peripheral.

  2. CC does not understand IC2 blocks natively, and requires a mod to make it able to use IC2 blocks as peripherals — if you don't have one installed, the MFE would count as "nothing" to wrap() and it will return nil. OpenCCSensors is one such mod.

  3. Another reason might be that somewhere before this code runs peripheral has been overwritten in some way, making the call to wrap() return nil.

  • [IMG]i61.tinypic.com/33lnslw.png[/IMG] These two images should help for you too see the sides and the code. also keep in mine i know my left and right but i changed them around for a second to check if it would work in reverse – Quelia Feb 15 '15 at 23:22
  • @Quelia I have a third suspicion then: you don't have the necessary CC addon mod installed to let CC talk to IC2 blocks. – SevenSidedDie Feb 15 '15 at 23:31
  • Questions like this are confusing. It's about a function in game, so it's valid on Arqade, but it's a coding problem, which would make it valid on SO as well haha – Ben Feb 15 '15 at 23:34
0

Where you got your code from, it says zo replace "side" with the side you have mfe/reactor on.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.