16 posts
Posted 15 August 2014 - 02:46 AM
I was doing some testing for turtle.detect() as I'm going to make my own tunneling script, and I made this simple script to test but I get an error.
http://www.pastebin.com/zGGEmVvmWhen I change the turtle.detect() == true to turtle.detect() == false, the script works fine.So why doesn't true work?I also triedif turtle.detect() then turtle.turnLeft()end
7508 posts
Location
Australia
Posted 15 August 2014 - 03:21 AM
please post the error message you're getting.
Edited on 15 August 2014 - 01:27 AM
1080 posts
Location
In the Matrix
Posted 15 August 2014 - 03:23 AM
Is there a block in front of the turtle?
7083 posts
Location
Tasmania (AU)
Posted 15 August 2014 - 05:42 AM
Bear in mind that Lua is case sensitive. "turtle.turnleft()" is not the same as "turtle.turnLeft()".
16 posts
Posted 15 August 2014 - 08:28 AM
I get the attempt to call nil error
I noticed that once I defined detect it worked, ex.
detect = turtle.detect()
if detect == true
turtle.turnLeft()
end
so that script works just fine for what I want to do, but do I HAVE to do it that way?
7508 posts
Location
Australia
Posted 15 August 2014 - 08:33 AM
the error
attempt to call nil means that the function you're trying to call does not exist. the common cause of this is a typo or incorrect capitalisation in the function.
There is no difference between
local detect = turtle.detect()
if detect then
turtle.turnLeft()
end
and
if turtle.detect() then
turtle.turnLeft()
end
meaning no, you don't
have to do it that way.
16 posts
Posted 15 August 2014 - 09:23 AM
the error
attempt to call nil means that the function you're trying to call does not exist. the common cause of this is a typo or incorrect capitalisation in the function.
There is no difference between
local detect = turtle.detect()
if detect then
turtle.turnLeft()
end
and
if turtle.detect() then
turtle.turnLeft()
end
meaning no, you don't
have to do it that way.
I used the bottom bit of code you put down and I put it in a turtle before I posted this. For some reason it wasn't working and now it is
7508 posts
Location
Australia
Posted 15 August 2014 - 11:04 AM
Chances are is that you had a typo in the function call.
2 posts
Posted 15 August 2014 - 01:51 PM
As Bomb Bloke said, Lua is case sensitive, so when your 'turtle.turnleft()' did not register as 'turtle.turnLeft()', which is the correct function.
16 posts
Posted 15 August 2014 - 08:33 PM
Trust me when I tell you that I checked the case of the letters
7508 posts
Location
Australia
Posted 16 August 2014 - 01:46 AM
To get an
attempt to call nil error there are three possibilities, no more, no less.
- The function doesn't exist at all; but since we know in this case it does its not this one,
- You've spelt the function name incorrectly;
- You've made a mistake in the capitalisation of the function;
8543 posts
Posted 16 August 2014 - 01:53 AM
Those pretty much all just boil down to, "the function you tried to call was nil." Oh, wait… :P/>