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

Attempt to compare nil with number error need help

Started by gheotic, 02 January 2013 - 07:09 AM
gheotic #1
Posted 02 January 2013 - 08:09 AM
im trying to improve my lumberjack script
i get this error when i type 1 i dont know what it is


Lumberjack2:47: Attempt to compare nil with number



local y = 0
local x = 0
local fuel = 1
local sappling = 2
local bone = 3

term.clear()
term.setCursorPos(1,1)
print("Should turtle plant too?")
write("Yes = 1 / No = 2): ")
local answer1 = tonumber(io.read())
if answer1 == 1 then
write("Loop: ")
local loop = tonumber(io.read())
term.setCursorPos(1,3)
else
loop = 1
end

print("Lumberjack has started")
m = peripheral.wrap("right")
m.link()
function Resupply()
m.resupply(fuel)
m.resupply(sappling)
m.resupply(bone)
end
function Refuel()
if turtle.getFuelLevel() < 20 then
Resupply()
turtle.select(fuel)
turtle.refuel(1)
end
end

while x < loop do -- the error is here somewhere this is line 47
Resupply()
if answer1 == 1 then
Refuel()
turtle.forward()
turtle.up()
turtle.select(sappling)
turtle.forward()
turtle.placeDown()
turtle.forward()
turtle.placeDown()
turtle.turnRight()
turtle.forward()
turtle.placeDown()
turtle.turnRight()
turtle.forward()
turtle.placeDown()
turtle.turnRight()
turtle.forward()
turtle.placeDown()
turtle.turnLeft()
turtle.forward()
turtle.down()
turtle.turnRight()
turtle.turnRight()
turtle.select(bone)
turtle.place()
turtle.place()
turtle.place()
--turtle.place()
turtle.turnRight()
turtle.turnRight()
turtle.forward()
turtle.turnRight()
turtle.turnRight()
turtle.select(fuel)
turtle.refuel(1)
end
turtle.forward()
turtle.dig()
turtle.forward()
turtle.dig()
turtle.forward()

turtle.turnRight()
turtle.dig()
turtle.forward()
turtle.turnRight()
turtle.dig()
turtle.forward()
turtle.turnRight()
turtle.dig()
turtle.forward()
turtle.turnRight()
print("Tree is ready to get cutted")
print("loop has started")
while turtle.detectUp() do
 
Refuel()
turtle.digUp()
turtle.forward()
turtle.digUp()
turtle.turnRight()
turtle.forward()
turtle.digUp()
turtle.turnRight()
turtle.forward()
turtle.digUp()
turtle.turnRight()
turtle.forward()
turtle.digUp()
turtle.turnRight()
turtle.up()
y = y + 1
end 

Refuel()
while not turtle.detectDown() do
turtle.down()
end
turtle.turnRight()
turtle.turnRight()
turtle.forward()
turtle.forward()
turtle.select(4)
turtle.drop(64)
turtle.select(5)
turtle.drop(64)
turtle.select(6)
turtle.drop(64)
turtle.turnLeft()
turtle.turnLeft()
turtle.select(fuel)
term.clear()
x = x + 1
end
term.setCursorPos(1,  1)
print("Turtle is done")
Doyle3694 #2
Posted 02 January 2013 - 01:25 PM
loop is not defined, And so it is nil. Add this to the top of your program:

local loop = 0