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

[1.51] turtle.getFacing (or getDirection)

Started by MudkipTheEpic, 03 March 2013 - 04:40 PM
MudkipTheEpic #1
Posted 03 March 2013 - 05:40 PM
The title is really it. All it is is a turtle function returning the way the turtle's front is facing. It can be coded, but is not reliable at all. Let's say you label the turtle and break it and replace it a different direction. The turtle would be confused. XP. Maybe 1 for north, 2 for east, 3 for south, and 4 for west. Just my 2 ( maybe even 3!!!) cents.

–Mudkip
theoriginalbit #2
Posted 03 March 2013 - 05:48 PM
MiscPeripherals — Compass Turtle
MudkipTheEpic #3
Posted 03 March 2013 - 05:50 PM
MiscPeripherals — Compass Turtle

Wow. I feel so stupid now. I even had MiscPeripherals installed! XP
Cranium #4
Posted 03 March 2013 - 06:40 PM
OR, without miscperipherals, you can use an indicator block or redstone signal. Have the turtle spin and detect until it finds the indicator, then re-orient itself properly. I've used this method reliably on vanilla CC.
Dlcruz129 #5
Posted 03 March 2013 - 07:05 PM
What if turtle.place() with a compass selected would return the direction? That seems plenty balanced to me; if you're willing to lose an inventory slot, you can get the turtle's direction?
theoriginalbit #6
Posted 03 March 2013 - 07:13 PM
What if turtle.place() with a compass selected would return the direction? That seems plenty balanced to me; if you're willing to lose an inventory slot, you can get the turtle's direction?
That could cause problems doing it that way, take the following (extremely basic) code, idk lets call it a hole in the wall repairer to stop people breaking into your house at that given location

while true do
  if not turtle.detect() then
    if not turtle.place() and turtle.getItemCount(1) then
      print("Failed to place block")
    else
      print("Saved your house")
    end
  end
end
Now if a compass returns the direction when place is used it will think that it has 'saved your house' when it actually hasn't placed anything…
MudkipTheEpic #7
Posted 03 March 2013 - 07:23 PM
Maybe a new turtle.interact function? Like for right-clicking but not placing?
theoriginalbit #8
Posted 03 March 2013 - 07:42 PM
Maybe a new turtle.interact function? Like for right-clicking but not placing?
I can see other uses for this…. like changing the delay on a repeater… not sure if they would implement for such small gain though…
MudkipTheEpic #9
Posted 03 March 2013 - 07:43 PM
Maybe a new turtle.interact function? Like for right-clicking but not placing?
I can see other uses for this…. like changing the delay on a repeater… not sure if they would implement for such small gain though…

Should I change the suggestion title and OP?
Kingdaro #10
Posted 03 March 2013 - 08:34 PM
Maybe a new turtle.interact function? Like for right-clicking but not placing?
I can see other uses for this…. like changing the delay on a repeater… not sure if they would implement for such small gain though…
I was going to make a suggestion on turtle.interact a while ago, and call it something like turtle.action, but interact does sound better.

It'd probably do more than change the delay on a repeater. You could open doors without using rs signals and LEAVE them open, activate levers, switches, trapdoors, pressure plates maybe? Perhaps even a monitor somehow.
Sebra #11
Posted 03 March 2013 - 08:55 PM

Now if a compass returns the direction when place is used it will think that it has 'saved your house' when it actually hasn't placed anything…
Let it return false, direction.
So logic will count false, but you still can get direction.
Dlcruz129 #12
Posted 04 March 2013 - 05:36 AM
No, I like the turtle.interact() idea. We could have it change repeater delay, get the direction it's facing, etc.
Cloudy #13
Posted 04 March 2013 - 06:23 AM
Turtles don't have hands.
Lyqyd #14
Posted 04 March 2013 - 06:51 AM
Requires GPS towers:


local vec1 = vector.new(gps.locate(2, false))
turtle.forward()
local vec2 = vector.new(gps.locate(2, false))
turtle.back()
local heading
if vec1 and vec2 then
  local resultVec = vec2 - vec1
  heading = ((resultVec.x + math.abs(resultVec.x) * 2) + (resultVec.z + math.abs(resultVec.z) * 3)) % 4
  --heading now contains a number 0-3 corresponding directly to the minecraft direction codes.
end
MudkipTheEpic #15
Posted 04 March 2013 - 07:54 AM
Requires GPS towers:


local vec1 = vector.new(gps.locate(2, false))
turtle.forward()
local vec2 = vector.new(gps.locate(2, false))
turtle.back()
local heading
if vec1 and vec2 then
  local resultVec = vec2 - vec1
  heading = ((resultVec.x + math.abs(resultVec.x) * 2) + (resultVec.z + math.abs(resultVec.z) * 3)) % 4
  --heading now contains a number 0-3 corresponding directly to the minecraft direction codes.
end

Thanks so much!
Kingdaro #16
Posted 04 March 2013 - 10:26 AM
Turtles don't have hands.
Nah, but logically, a turtle could push itself into a button, lever or pressure plate, and again only logically, push a door open, if it were able to move freely.
Left4Cake #17
Posted 04 March 2013 - 03:09 PM
Turtles don't have hands.
Nah, but logically, a turtle could push itself into a button, lever or pressure plate, and again only logically, push a door open, if it were able to move freely.

It could also push buttons by pushing it with its tool.
Pharap #18
Posted 06 March 2013 - 05:22 PM
Turtles don't have hands.
How do they write signs and use flint and steels then?
Or craft for that matter?

Turtles don't have hands.
Nah, but logically, a turtle could push itself into a button, lever or pressure plate, and again only logically, push a door open, if it were able to move freely.
Point duly noted.

What if turtle.place() with a compass selected would return the direction? That seems plenty balanced to me; if you're willing to lose an inventory slot, you can get the turtle's direction?
That could cause problems doing it that way, take the following (extremely basic) code, idk lets call it a hole in the wall repairer to stop people breaking into your house at that given location

while true do
  if not turtle.detect() then
	if not turtle.place() and turtle.getItemCount(1) then
	  print("Failed to place block")
	else
	  print("Saved your house")
	end
  end
end
Now if a compass returns the direction when place is used it will think that it has 'saved your house' when it actually hasn't placed anything…
Not a very good argument, this is already possible in the current system.
What if the turtle is holding flint and steel? You just set fire to your house, which is probably worse.

A turtle needing a compass would make things more balanced as compasses aren't exactly cheap anyway.
Obviously turtle.place() doesn't make much sense with a compass since you aren't actually placing anything, but then again, 'placing' a flint and steel places fire, not the flint and steel itself.

So either adding turtle.interact or reusing turtle.place for compass compatibility would be pretty handy. On top of that it's hardly going to make any peripherals redundant overnight.