This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Miiscakes's profile picture

Error: startup:5: attempt to call nil

Started by Miiscakes, 18 March 2015 - 07:04 PM
Miiscakes #1
Posted 18 March 2015 - 08:04 PM
Hi, i copied a program that i saw on youtube, but when im trying to start the program it said this error : "startup:5: attempt to call nil", in the movie, it's exactly the same program but it works ! Help me please :(/>

reactor = peripheral.wrap("back")
cell = peripheral.wrap("left")

actif = reactor.getActive()
maxCell = cube.getMaxEnergy()

while true do

energystore = cell.getStored()
level = (energystore*100)/maxCell

if actif then
if level >= 75 then reactor.setActive(false) end
else
if level <= 25 then reactor.setActive(true) end
end

sleep(1)

end
HPWebcamAble #2
Posted 18 March 2015 - 11:08 PM
First, use code tags to make code look nicer:
[.code] [./code] (without the periods)

Now, line 5 is this:

maxCell = cube.getMaxEnergy()

'cube' is nil, so the line errors.

Above, I noticed you wrap a few peripherals

reactor = peripheral.wrap("back")
cell = peripheral.wrap("left")

Judging from the rest of the program, 'cube' should be 'cell'

maxCell = cell.getMaxEnergy() --# Just change cube to cell

Also, make sure you actually have the reactor on the back and the cell on the left
You can change the side name if need to move them