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

Attempt to call nil

Started by omnee, 10 April 2013 - 10:43 AM
omnee #1
Posted 10 April 2013 - 12:43 PM
I know this error usualy happens when I call a function before I've declared it, but I didn't do it so…


print("Plant trees? Y or N?")
modo=io.read()

-- turtle inv: slot1=fuel slot2=bonemeal slot3=log slot4=sapling rest=1 piece of wood

function comparar()
	    turtle.select(3)
	    while turtle.compare() do
			    turtle.dig()
			    turtle.forward()
	    end
end

function plantar()
	    turtle.select(4)
	    if turtle.detect()==false then
			    turtle.place()
			    turtle.select(2)
			    turtle.place()
	    end
end

function detectar()
	    while turtle.detectUp() do
			    turtle.digUp()
			    turtle.up()
	    end
end

function voltar()
	    while not turtle.detectDown() do
			    turtle.down()
	    end
	    turtle.back()
end

function cortarArvorePlantar()
	    if modo=="Y" then
			    comparar()
			    detectar()
			    voltar()
			    plantar()
	    else if modo=="N" then
			    comparar()
			    detectar()
			    voltar()
	    end
end

function cortarMover()
	    turtle.forward()
	    turtle.forward()
	    turtle.turnRight()
	    cortarArvore()
	    turtle.turnLeft()
end

function cortarCurva()
	    turtle.forward()
	    turtle.turnLeft()
	    turtle.forward()
	    turtle.turnRight()
	    cortarArvore()
	    turtle.turnLeft()
end

function cortarInicio()
	    turtle.forward()
	    turtle.turnRight()
	    cortarArvore()
	    turtle.turnLeft()
end

function restock()
	    turtle.turnRight()
	    turtle.turnRight()
	    turtle.suck()
	    turtle.turnRight()
	    turtle.turnRight()
end

function usarFuel()
	    while turtle.getFuelLevel()<=100 do
			    turtle.select(1)
			    turtle.refuel(5)
	    end
end

function depositar()
	    wood=turtle.getItemCount(1)
	    turtle.turnRight()
	    turtle.turnRight()
	    turtle.select(3)
	    repeat
			    turtle.drop(1)
	    until wood==1
	    end
	    turtle.turnRight()
	    turtle.turnRight()
end

function fim()
	    turtle.forward()
	    turtle.turnLeft()
	    turtle.select(1)
end
	  
function cortarTudo()
	    usarFuel()
	    restock()
	    cortarInicio()
	    cortarMover()
	    cortarMover()
	    cortarMover()
	    cortarCurva()
	    cortarMover()
	    cortarMover()
	    cortarCurva()
	    cortarMover()
	    cortarMover()
	    cortarMover()
	    cortarCurva()
	    cortarMover()
	    cortarMover()
	    fim()
	    depositar()
end

cortarTudo()

Any Idea? :xxx
SadKingBilly #2
Posted 10 April 2013 - 12:49 PM
One problem I see is the line else if modo=="N"then. It should be elseif modo == "N" then. You also call a function named cortarArvore() three times, but you haven't declared anything by that name; I think you meant to call cortarArvorePlantar(). And in the depositar() function, remove the end. That's all I can see.
omnee #3
Posted 11 April 2013 - 03:50 AM
One problem I see is the line else if modo=="N"then. It should be elseif modo == "N" then. You also call a function named cortarArvore() three times, but you haven't declared anything by that name; I think you meant to call cortarArvorePlantar(). And in the depositar() function, remove the end. That's all I can see.

Oh, Thanks, I never noticed that it was cortarArvore() and not cortarArvorePlantar()