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

Block detector?

Started by orevilo, 19 June 2012 - 04:30 AM
orevilo #1
Posted 19 June 2012 - 06:30 AM
Hi, first time posting, sorry if this is in the wrong place.

I am trying to write a program that will detect when cobble appears in front of a turtle and the when it does to mine it. Problem is however I have little experience in coding and have no experience with Lua. I can't imagine this being impossible to do. I just don't know how. If anyone would like to point me in the right direction, or better yet link me to someone who has done this (I could not find anyone), that would be great.

Thanks,
Orevilo
BigSHinyToys #2
Posted 19 June 2012 - 07:31 AM
It is not possible to detect when a block updates or is placed near a turtle. But you want a cobble gen so here is the simplest one possible.


while true do
	turtle.dig()
	sleep(2)
end

Example usage

tfoote #3
Posted 19 June 2012 - 05:38 PM
Use this:
1) Put 1 cobblestone in slot 1
2) Use this code:

turtle.select(1)
while true do
x = turtle.getItemCount(1)
if x == 64 then -- if there are 64 cobblestone in the slot it will turn around and spit 63 out...
turtle.turnRight()
turtle.turnRight()
turtle.drop(63)
turtle.turnRight()
turtle.turnRight()
end
if turtle.detect() == true then -- detects for block in front
if turtle.compare() == true then -- checks to see if it is cobblestone
turtle.dig() -- digs if it is the same
else
--what you want it to do if it isn't cobblestone
end
else -- if there isn't a block in front
-- what you want to do if there isn't a block in front
end
sleep(2)
end
-- NOTICE: Whatever you put in slot 1 (top left) is what it will check for and mine...

Let me know if you have any questions
kazagistar #4
Posted 19 June 2012 - 08:52 PM
If you make it sleep 0.05 or so, you can make it faster then a redpower breaker, but the server SHOULD be ok.
tfoote #5
Posted 20 June 2012 - 12:19 AM
I want to know how you are going to use this… cuz im pretty sure that if this turtle is stationary that cobblestone/stone don't fall…
orevilo #6
Posted 20 June 2012 - 04:53 AM
Thanks for the feed back! it works perfect!