–Mudkip
This is a read-only snapshot of the ComputerCraft forums,
taken in April 2020.
[1.51] turtle.getFacing (or getDirection)
Started by MudkipTheEpic, 03 March 2013 - 04:40 PMPosted 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
–Mudkip
Posted 03 March 2013 - 05:48 PM
MiscPeripherals — Compass Turtle
Posted 03 March 2013 - 05:50 PM
MiscPeripherals — Compass Turtle
Wow. I feel so stupid now. I even had MiscPeripherals installed! XP
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.
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?
Posted 03 March 2013 - 07:13 PM
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 locationWhat 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?
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…Posted 03 March 2013 - 07:23 PM
Maybe a new turtle.interact function? Like for right-clicking but not placing?
Posted 03 March 2013 - 07:42 PM
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…Maybe a new turtle.interact function? Like for right-clicking but not placing?
Posted 03 March 2013 - 07:43 PM
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…Maybe a new turtle.interact function? Like for right-clicking but not placing?
Should I change the suggestion title and OP?
Posted 03 March 2013 - 08:34 PM
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.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…Maybe a new turtle.interact function? Like for right-clicking but not placing?
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.
Posted 03 March 2013 - 08:55 PM
Let it return false, direction.…
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…
So logic will count false, but you still can get direction.
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.
Posted 04 March 2013 - 06:23 AM
Turtles don't have hands.
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
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!
Posted 04 March 2013 - 10:26 AM
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.Turtles don't have hands.
Posted 04 March 2013 - 03:09 PM
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.Turtles don't have hands.
It could also push buttons by pushing it with its tool.
Posted 06 March 2013 - 05:22 PM
How do they write signs and use flint and steels then?Turtles don't have hands.
Or craft for that matter?
Point duly noted.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.Turtles don't have hands.
Not a very good argument, this is already possible in the current system.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 locationWhat 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?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…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
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.