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

turtle.detect(Left, Right ,Back)

Started by Spongy141, 03 April 2013 - 07:28 PM
Spongy141 #1
Posted 03 April 2013 - 09:28 PM
Basically I think it would be nice to allow turtles to detect left or right, and back, it would allow for users to make a AI for turtles easier, like

turtle.detect("Left")
turtle.detect("Right")
turtle.detect("Back")
OR
turtle.detectRight()
turtle.detectLeft()
turtle.detectBack()
This will allow for AI programs to take up less time and space to make.
TheArchitect #2
Posted 03 April 2013 - 10:08 PM
turtle.detectLeft()

is exactly the same as

turtle.turnLeft()
turtle.detect()

It's not like you couldn't write your own function to take care of that. Let me do that for you while I'm at it:


function detectLeft()
  turtle.turnLeft()
  turtle.detect()
end

There.
Spongy141 #3
Posted 03 April 2013 - 10:24 PM
I knew that, but it forces the turtle to move more often, when it could not have to turn at all and still detect a side. Also you still can't detect if a block is behind it or not without having it turn around EVERYTIME (If your trying to make a AI).
Engineer #4
Posted 03 April 2013 - 10:29 PM
Just from reading other threads here, they wont add it because you can do that already.

Correct me if Im wrong about the 'wont add it' part.
theoriginalbit #5
Posted 03 April 2013 - 10:50 PM
turtle.detectLeft()

is exactly the same as

turtle.turnLeft()
turtle.detect()
Not really. the aim of him posting this is to be able to have the turtle move around quicker. for example with my remote turtle program I am making, it displays if there are blocks on each side of it. this requires that with EACH move it makes it must turn to check the sides, this take ~1 second to do. that means that the turtle is extremely slow… having, at the very least, a detectLeft and a detectRight would drastically speed up turtle movement when the person is making an AI…

however I vaguely remember someone asking about this quite a while ago and iirc the devs have a very good reason for these not being in existence. I could be wrong tho. my memory is bad :P/>
Bubba #6
Posted 04 April 2013 - 12:43 AM
Also you still can't detect if a block is behind it or not without having it turn around EVERYTIME (If your trying to make a AI).

Sure you can. First off, keep track of where the turtle has been. If you just came from somewhere, it's pretty unlikely that a block will suddenly have appeared as long as people aren't interfering with the turtle. But just in case, you can always check whether the turtle can move back or not. More effecient than turning all the way around twice.

I happen to agree with this addition though, and I don't feel like it would be overpowered either. I don't feel that a compare function is necessary, but just detecting whether a block is there or not efficiently could be enormously beneficial.
Engineer #7
Posted 04 April 2013 - 02:43 AM
You could also use: turtle.back()

If it returns true then there is no block. You have to move forward again.
If it is false, then there is a block there.

But if you want to constantly check, then this method isnt usefull. It is then a 'fuel-waster'
Cloudy #8
Posted 04 April 2013 - 05:29 AM
Been declined time and time again. The turtle cannot detect left or right, or behind itself, and that isn't going to change.
theoriginalbit #9
Posted 04 April 2013 - 05:41 AM
Been declined time and time again. The turtle cannot detect left or right, or behind itself, and that isn't going to change.
I knew I had remembered it before… what was the reasoning for it not having it again? was it something to do with peripherals or something?
Cranium #10
Posted 04 April 2013 - 05:47 AM

function detectBack()
	turtle.turnRight()
    turtle.turnRight()
    if not turtle.detect() then
	    turtle.turnLeft()
	    turtle.turnLeft()
	    return false
    end
    turtle.turnRight()
    turtle.turnRight()
    return true
end

function detectLeft()
	turtle.turnLeft()
	if not turtle.detect() then
	    turtle.turnRight
		return false
	end
    turtle.turnRight()
	return true
end

function detectRight()
	turtle.turnRight()
	if not turtle.detect() then
	    turtle.turnLeft()
		return false
	end
    turtle.turnLeft()
	return true
end
There is the functions you need. I don't see why, other than needing to speed up your turtles, you would need to add this into the default. Turtles have always, and most likely will only ever be able to detect, place, interact with things in front, below, or above them.

Edit: Changed to not consume fuel, and to return to starting position.
Edited on 04 April 2013 - 03:53 AM
theoriginalbit #11
Posted 04 April 2013 - 05:48 AM
other than needing to speed up your turtles, you would need to add this into the default
less fuel usage… moving back then forward again could waste a lot of fuel if checking often.
Lyqyd #12
Posted 04 April 2013 - 06:37 AM
Locked under the "enhancements" clause of the TNtS list.