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

Simple turtle.detect() program

Started by AdrenalineDM, 15 August 2014 - 12:46 AM
AdrenalineDM #1
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/zGGEmVvm
When I change the turtle.detect() == true to turtle.detect() == false, the script works fine.
So why doesn't true work?
I also tried

if turtle.detect() then
turtle.turnLeft()
end
theoriginalbit #2
Posted 15 August 2014 - 03:21 AM
please post the error message you're getting.
Edited on 15 August 2014 - 01:27 AM
Dragon53535 #3
Posted 15 August 2014 - 03:23 AM
Is there a block in front of the turtle?
Bomb Bloke #4
Posted 15 August 2014 - 05:42 AM
Bear in mind that Lua is case sensitive. "turtle.turnleft()" is not the same as "turtle.turnLeft()".
AdrenalineDM #5
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?
theoriginalbit #6
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.
AdrenalineDM #7
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
theoriginalbit #8
Posted 15 August 2014 - 11:04 AM
Chances are is that you had a typo in the function call.
Maxskywalker #9
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.
AdrenalineDM #10
Posted 15 August 2014 - 08:33 PM
Trust me when I tell you that I checked the case of the letters
theoriginalbit #11
Posted 16 August 2014 - 01:46 AM
To get an attempt to call nil error there are three possibilities, no more, no less.
  1. The function doesn't exist at all; but since we know in this case it does its not this one,
  2. You've spelt the function name incorrectly;
  3. You've made a mistake in the capitalisation of the function;
Lyqyd #12
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/>