Jump to content




Getting where a turtle is facing not working?


  • You cannot reply to this topic
4 replies to this topic

#1 mrpoopy345

  • Members
  • 148 posts
  • LocationMy Computer

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 by mrpoopy345, 06 March 2015 - 01:17 AM.


#2 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

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).

#3 mrpoopy345

  • Members
  • 148 posts
  • LocationMy Computer

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 by mrpoopy345, 06 March 2015 - 12:27 PM.


#4 mrpoopy345

  • Members
  • 148 posts
  • LocationMy Computer

Posted 06 March 2015 - 04:51 PM

Found the problem, didn't have fuel in the turtle *facepalm*

#5 The_Cat

  • Members
  • 119 posts

Posted 06 March 2015 - 05:22 PM

View Postmrpoopy345, on 06 March 2015 - 04:51 PM, said:

Found the problem, didn't have fuel in the turtle *facepalm*

Make a check fuel function now :lol:





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users