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

Cheesety210 Error Forum

Started by Cheesety210, 01 April 2013 - 05:22 AM
Cheesety210 #1
Posted 01 April 2013 - 07:22 AM
I end up having a LOT of mistakes in my code, and so half of the forum page isn't filled with my topics, I'm going to be posting my errors here and hope that someone comes to my rescue!
Cheesety210 #2
Posted 01 April 2013 - 07:23 AM

function checkfuel()
if turtle.getFuelLevel <= 10 then
turtle.select(1)
turtle.refuel()
end
end
function mineup()
repeat
turtle.digUp()
turtle.up()
until turtle.detectUp() == false
repeat
turtle.down()
until turtle.detectDown() == true
end
function ddf()
if turtle.detect() == true then
turtle.dig()
turtle.forward()
else
turtle.forward()
end
end
print("Hello. Welcome to the Cheesety210 Tree cutting program")
print("Please put your fuel in the first slot.")
turtle.turnRight()
turtle.turnRight()
turtle.turnRight()
turtle.turnRight()
term.clear()
print("I should be placed at the bottom of a tree next to it")
print("right next to the tree. A diagram is below.")
print(" [ ] = A log, and T is the turtle")
print("[ ] [ ] ")
print("[ ] [ ] ")
print(" T	  ")
print(" What is the width/length of the tree? In the example above it's 2.")
local length = read()
if length == 1 then
checkfuel()
ddf()
mineup()
end
if length == 2 then
checkfuel()
ddf()
mineup()
checkfuel()
ddf()
mineup()
checkfuel()
turtle.turnRight()
ddf()
mineup()
checkfuel()
turtle.turnRight()
ddf()
mineup()
checkfuel()
turtle.forward()
end
if length == 3 then
ddf()
mineup()
checkfuel()
ddf()
mineup()
checkfuel()
ddf()
mineup()
checkfuel()
turtle.turnRight()
ddf()
mineup()
checkfuel()
turtle.turnRight()
ddf()
mineup()
checkfuel()
ddf()
mineup()
checkfuel()
turtle.turnLeft()
ddf()
mineup()
checkfuel()
turtle.turnLeft()
ddf()
mineup()
checkfuel()
ddf()
mineup()
end
print("I am done with this tree!")

This works fine up until when it declares length = read().
I enter 1,2, or 3, and it completely skips the "if length == " parts, and prints "I am done with this tree!", which is the last line to show the turtle has done it's job.
LBPHacker #3
Posted 01 April 2013 - 07:27 AM
tonumber the input:
length = tonumber(read())

EDIT: You shouldn't make a topic for your all-time questions. You make the life of the ones like you who're stuck with their code when they're trying to find the answer in the topics, hoping they don't have to ask something again if it was asked in the past. And moderators don't like it.
Cheesety210 #4
Posted 01 April 2013 - 08:26 AM
I got an error with that "attempt to compare __le on function and number"
LBPHacker #5
Posted 01 April 2013 - 08:32 AM
That means you are trying to compare a function and a number (line 2 in the box: turtle.getFuelLevel <= 10)

Keep in mind: functions return something only if you CALL them.
if turtle.getFuelLevel() <= 10 then