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

Getting where a turtle is facing not working?

Started by mrpoopy345, 06 March 2015 - 12:17 AM
mrpoopy345 #1
Posted 06 March 2015 - 01:17 AM
I am trying to make turtles that can see using new command computers, but for some reason whenever I run the turtle code getOrientation always returns 0
Turtle code:
  
rednet.open("left")		
function getOrientation()		
loc1 = vector.new(gps.locate(2, false))		
if not turtle.forward() then		
	for j=1,6 do		
			if not turtle.forward() then		
					turtle.dig()		
		 else break end		
	end		
end		
loc2 = vector.new(gps.locate(2, false))		
heading = loc2 - loc1		
return ((heading.x + math.abs(heading.x) * 2) + (heading.z + math.abs(heading.z) * 3))		
end		
pos = getOrientation()		
print(pos)		
x, y, z = gps.locate(2)		
if pos == 1 then		
rednet.send(12, x-1)		
rednet.send(12, y)		
rednet.send(12, z)		
print("1")		
elseif pos == 2 then		
rednet.send(12, x)		
rednet.send(12, y)		
rednet.send(12, z-1)		
print("2")		
elseif pos == 3 then		
rednet.send(12, x+1)		
rednet.send(12, y)		
rednet.send(12, z)		
print("3")		
elseif pos == 4 then		
rednet.send(12, x)		
rednet.send(12, y)		
rednet.send(12, z+1)		
print("4")		
end		
Does anyone know why?
Edited on 06 March 2015 - 12:17 AM
Bomb Bloke #2
Posted 06 March 2015 - 04:31 AM
Silly question, but did you set up enough Command Computers? You'll need at least four GPS hosts in range, layed out in such a way that it's possible to pinpoint a position, or else gps.locate() will return nil once your two-second time-out expires (which will result in your vectors both being set to 0,0,0).
mrpoopy345 #3
Posted 06 March 2015 - 12:12 PM
I did set up enough gps computers, and I have tested and gps.locate(2) works fine. I think maybe the problem might lay in the fact that my code uses turtle.dig and I am using a regular turtle, which I have to do because there is no such thing as a wireless mining turtle (Side question: Does anyone know what happened to them?)

Edit: Found out how wireless mining turtles work now, equipped a pickaxe and it still doesn't work.
Edited on 06 March 2015 - 11:27 AM
mrpoopy345 #4
Posted 06 March 2015 - 04:51 PM
Found the problem, didn't have fuel in the turtle *facepalm*
The_Cat #5
Posted 06 March 2015 - 05:22 PM
Found the problem, didn't have fuel in the turtle *facepalm*

Make a check fuel function now :lol:/>