Im getting a error message in my computercraft computer

Im getting a error message in my computercraft computer - Side view of young female in casual clothes typing message on laptop while sitting at wooden table in kitchen

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)


Best Answer

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.




Pictures about "Im getting a error message in my computercraft computer"

Im getting a error message in my computercraft computer - Expressive angry businessman in formal suit looking at camera and screaming with madness while hitting desk with fist
Im getting a error message in my computercraft computer - Amazed formal male looking at laptop screen
Im getting a error message in my computercraft computer - Focused young woman with laptop and smartphone in modern apartment



How do I connect my computer to my ComputerCraft turtle?

Start \u201cclient\u201d on the turtle. Start \u201cremote\u201d on the pocket computer and input the turtle ID (printed on start of \u201cclient\u201d) You can reconnect as many times as you want, and you can have as many remotes for one turtle as you want.

What code does ComputerCraft use?

You program computers and turtles in ComputerCraft using a language called Lua. Lua is easy to learn and use, and it's perfect for learning essential programming concepts.

How do you use computers in ComputerCraft?

The Computer (pictured) is the main block of ComputerCraft. From the Computer, you will be able to make programs, turn on and off Redstone, use Rednet, play games, and much more....Keyboard Shortcuts.ShortcutUsageCTRL + RReboots the console.CTRL + SForcefully shuts down the computer.1 more row•Aug 4, 2020

How do you exit a program in ComputerCraft?

But note that Minecraft ComputerCraft may provide a different function than the standard os. exit one. Show activity on this post. You can also terminate it manually by holding down Ctrl + T a few seconds in the turtle/computer's interface.



Troubleshooting Error Messages in Your Code




More answers regarding im getting a error message in my computercraft computer

Answer 2

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

Sources: Stack Exchange - This article follows the attribution requirements of Stack Exchange and is licensed under CC BY-SA 3.0.

Images: EKATERINA BOLOVTSOVA, Andrea Piacquadio, Andrea Piacquadio, Vlada Karpovich