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

[Lua] attempt to call nil

Started by tribalthomas, 05 February 2013 - 07:43 AM
tribalthomas #1
Posted 05 February 2013 - 08:43 AM
topic:[Lua] attempt to call nil

i wanted to cut down large trees without having to go though loads of work climbing up and down trees. so i tried to make a turtle program but it isnt working right. can someone tell me what i did wrong.

the error message says

lumberjack:6: attempt to call nil

also it cuts down the first block on the tree then it gives that error message.




while turtle.detect() do
turtle.dig()
turtle.up()
end
while not turtle.detect and not turtle.detectdown() do
turtle.down()
end

Cranium #2
Posted 05 February 2013 - 08:46 AM
turtle.detect needs to be turtle.detect(), and turtle.detectdown() needs to be turtle.detectDown().
Just some syntax and capitalization errors.
tribalthomas #3
Posted 05 February 2013 - 08:50 AM
thanks for your help
tribalthomas #4
Posted 05 February 2013 - 08:52 AM
new problem now it only cuts the first block it doesnt go up
Cranium #5
Posted 05 February 2013 - 08:56 AM
That's because once it digs the first log, it no longer detects anything in front of it.
You might want to do this:

turtle.dig() --digs first block
turtle.forward() --moves under tree
while turtle.detectUp() do --will go until nothing is abov the turtle
    turtle.digUp()
    turtle.up()
end
while not turtle.detectDown() do --will go down until at floor level
    turtle.down()
end
turtle.back() --will move back to original starting place.
tribalthomas #6
Posted 05 February 2013 - 09:06 AM
thanks i will try that
tribalthomas #7
Posted 05 February 2013 - 09:16 AM
new error [string"lumberjack"]:5: '=' expected

i didnt add the last part about moving it back to original place because i didnt really think it was needed.


turtle.dig()
turtle.forward
while turtle.detectUp() do
	   turtle.digUp
	   turtle.Up
end
while not turtle.detectDown
		 turtle.down()
end
tribalthomas #8
Posted 05 February 2013 - 09:24 AM
ok i fixed that problem but now its not moving forward i dont know why
Cranium #9
Posted 05 February 2013 - 09:28 AM
turtle.forward needs to be turtle.forward()
Need to remember the parenthesis
tribalthomas #10
Posted 05 February 2013 - 09:30 AM
it is still not working
any other ideas
Cranium #11
Posted 05 February 2013 - 09:32 AM

turtle.dig()
turtle.forward()
while turtle.detectUp() do
    turtle.digUp()
    turtle.up()
end
while not turtle.detectDown()
    turtle.down()
end
This does work. With the parenthesis, it will work.
tribalthomas #12
Posted 05 February 2013 - 09:39 AM
thanks for you help im sorry for wasting your time i cant get it to work and im done trying
trollsama #13
Posted 05 February 2013 - 12:35 PM
I wouldn't give up so easy, Not too long ago i was in the same boat as you, getting incredibly frustrated, spending hours on small/simple programs that would never seem to work.
if you can tough it out past the first bit of the curve, the rest will start to come to you with much less trouble.
The API list on the wiki, despite not having every API is still a powerful tool.
using that in combination with a video tutorial here and there, and doing just as you did, asking for help on the forums you will learn quickly.

just remember that lua is in cammelCase (instead of spaces you capitalize the first letter of every word after the first one. soYouDoThis.)
and that the brackets, even if they are empty a lot of the time, do matter, and are a must.


P.S. you are not wasting anyone's time, any reply's that come in are completely voluntary. Many of the members helping on here, have received help themselves and want to give back :)/>