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

attempt to call nil setFacing program

Started by meeko011, 20 June 2014 - 04:50 PM
meeko011 #1
Posted 20 June 2014 - 06:50 PM
I've read through this program several times and I can't seem to find the miss-spelled function.

setFacing:6: attempt to call nil


local tArgs = ...
rednet.open("right")
local x,y,z = gps.locate(5)
setFacing(tArgs)
function getFacing()
turtle.dig()
turtle.forward()
x2,y2,z2 = gps.locate(5)
if x2 > x then
  facing = 3
end
if x > x2 then
  facing = 1
end
turtle.back()
turtle.turnRight()
turtle.dig()
turtle.forward()
x2,y2,z2 = gps.locate(5)
if z2 > z then
  facing = 0
end
if z > z2 then
  facing = 2
end
turtle.back()
turtle.turnLeft()
end

function setFacing(face)
getFacing()
while not facing == face do
  turtle.turnRight()
  getFacing()
end
end
Lignum #2
Posted 20 June 2014 - 06:57 PM
turtle.dig can't be found.
Does the turtle have a tool equipped that it can dig with? A sword won't work.
meeko011 #3
Posted 20 June 2014 - 07:24 PM
He has a pickaxe. I even removed all the dig functions but got the same error.
Lignum #4
Posted 20 June 2014 - 07:31 PM
The error message is referring to line 6, which is where turtle.dig is, which is what made me think that.
However, you seem to be calling setFacing before it exists on line 4. Try moving that call to the end of the file.
meeko011 #5
Posted 20 June 2014 - 08:17 PM
That worked! Thank you.